Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need working sample for OOP Background Task used in WinUI3 / WindowsAppSDK app #1327

Closed
myokeeh opened this issue May 11, 2023 · 11 comments
Closed
Assignees
Labels
enhancement New feature or request

Comments

@myokeeh
Copy link

myokeeh commented May 11, 2023

I am really struggling to get a working OOP background task in a UWP app I'm trying to convert over to WinUI3 / WIndowsAppSDK.

Please provide a working sample.

I've tried following through the sample and referenced docs, but I still can't get it to display a simple toast notification.

Also, how can I debug the OOP background task? The way I know how to do it with the old UWP version no longer works.

@myokeeh myokeeh added the enhancement New feature or request label May 11, 2023
@manodasanW manodasanW self-assigned this May 11, 2023
@Osirisoo0O
Copy link

Here is my sample: https://github.com/Osirisoo0O/WASDKSample
Hope to help you.

@myokeeh
Copy link
Author

myokeeh commented May 12, 2023

@Osirisoo0O thank you. With that, I at least know it works. I did have to change the following for it to work for me:

changed MyButton_Click to myButton_Click

changed to _myusername_ in task csproj file below.

  <ItemGroup>
    <None Update="C:\Users\_myusername_\.nuget\packages\microsoft.windows.cswinrt\2.0.2\hosting\x64\native\WinRT.Host.dll">
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </None>
  </ItemGroup>

Now the remaining things to address:

Severity	Code	Description	Project	File	Line	Suppression State
Error	APPX1101	Payload contains two or more files with the same destination path 'Microsoft.InteractiveExperiences.Projection.dll'. Source files: 
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\lib\net6.0-windows10.0.18362.0\Microsoft.InteractiveExperiences.Projection.dll
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.0.0\lib\net5.0-windows10.0.18362.0\Microsoft.InteractiveExperiences.Projection.dll	MYAPP	
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\buildTransitive\Microsoft.Build.Msix.Packaging.targets	1500	

Error	APPX1101	Payload contains two or more files with the same destination path 'Microsoft.WinUI.dll'. Source files: 
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\lib\net6.0-windows10.0.18362.0\Microsoft.WinUI.dll
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.0.0\lib\net5.0-windows10.0.18362.0\Microsoft.WinUI.dll	MYAPP	
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\buildTransitive\Microsoft.Build.Msix.Packaging.targets	1500	

Error	APPX1101	Payload contains two or more files with the same destination path 'Microsoft.Windows.AppLifecycle.Projection.dll'. Source files: 
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.AppLifecycle.Projection.dll
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.0.0\lib\net5.0-windows10.0.18362.0\Microsoft.Windows.AppLifecycle.Projection.dll	MYAPP	
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\buildTransitive\Microsoft.Build.Msix.Packaging.targets	1500	

Error	APPX1101	Payload contains two or more files with the same destination path 'Microsoft.Windows.ApplicationModel.DynamicDependency.Projection.dll'. Source files: 
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.DynamicDependency.Projection.dll
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.0.0\lib\net5.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.DynamicDependency.Projection.dll	MYAPP	
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\buildTransitive\Microsoft.Build.Msix.Packaging.targets	1500	

Error	APPX1101	Payload contains two or more files with the same destination path 'Microsoft.Windows.ApplicationModel.Resources.Projection.dll'. Source files: 
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.Resources.Projection.dll
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.0.0\lib\net5.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.Resources.Projection.dll	MYAPP	
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\buildTransitive\Microsoft.Build.Msix.Packaging.targets	1500	

Error	APPX1101	Payload contains two or more files with the same destination path 'Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll'. Source files: 
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.0.0\lib\net5.0-windows10.0.18362.0\Microsoft.Windows.ApplicationModel.WindowsAppRuntime.Projection.dll	MYAPP	
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\buildTransitive\Microsoft.Build.Msix.Packaging.targets	1500	

Error	APPX1101	Payload contains two or more files with the same destination path 'Microsoft.Windows.System.Power.Projection.dll'. Source files: 
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\lib\net6.0-windows10.0.18362.0\Microsoft.Windows.System.Power.Projection.dll
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.0.0\lib\net5.0-windows10.0.18362.0\Microsoft.Windows.System.Power.Projection.dll	MYAPP	
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\buildTransitive\Microsoft.Build.Msix.Packaging.targets	1500	

Error	APPX1101	Payload contains two or more files with the same destination path 'Microsoft.WindowsAppRuntime.Bootstrap.Net.dll'. Source files: 
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\lib\net6.0-windows10.0.18362.0\Microsoft.WindowsAppRuntime.Bootstrap.Net.dll
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.0.0\lib\net5.0-windows10.0.18362.0\Microsoft.WindowsAppRuntime.Bootstrap.Net.dll	MYAPP	
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\buildTransitive\Microsoft.Build.Msix.Packaging.targets	1500	

Error	APPX1101	Payload contains two or more files with the same destination path 'Newtonsoft.Json.dll'. Source files: 
C:\Users\_myusername_\.nuget\packages\newtonsoft.json\13.0.3\lib\net6.0\Newtonsoft.Json.dll
C:\Users\_myusername_\.nuget\packages\newtonsoft.json\13.0.1\lib\netstandard2.0\Newtonsoft.Json.dll	MYAPP	
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\buildTransitive\Microsoft.Build.Msix.Packaging.targets	1500	

Error	APPX1101	Payload contains two or more files with the same destination path 'System.Management.dll'. Source files: 
C:\Users\_myusername_\.nuget\packages\system.management\6.0.0\runtimes\win\lib\net6.0\System.Management.dll
C:\Users\_myusername_\.nuget\packages\system.management\6.0.0\lib\net6.0\System.Management.dll	MYAPP	
C:\Users\_myusername_\.nuget\packages\microsoft.windowsappsdk\1.3.230502000\buildTransitive\Microsoft.Build.Msix.Packaging.targets	1500	

Related: #1243

@manodasanW
Copy link
Member

@myokeeh I think your remaining errors can be addressed by moving your projects to the same version of WinAppSDK. It seems one is using 1.3 while other is on 1.0?

@myokeeh
Copy link
Author

myokeeh commented May 12, 2023

@manodasanW The only project referencing WindowsAppSDK is the app. The other two projects are just the background task and a class library. The WinUI3 app and class library were generated with Template Studio.

@Osirisoo0O
Copy link

@myokeeh Try to delete WindowsAppSDK 1.0 nuget?
I have similar problems. Resolved by manually replacing files.

@myokeeh
Copy link
Author

myokeeh commented May 12, 2023

@Osirisoo0O I've cleared my Nuget cache and just manually deleted "microsoft.windowsappsdk\1.0.0", but rebuilding the solution brings it back.

How do I tell it to ignore 1.0.0?

Also, in your sample, you have 'Microsoft.Windows.SDK.BuildTools' Is that needed? I removed it on your sample and it still seems to work fine. I added it to my project to try--did not help.

@Osirisoo0O
Copy link

Maybe the problem from Template Studio.
This sample created since wasdk 1.0 or before, so I don't check it.

@myokeeh
Copy link
Author

myokeeh commented May 13, 2023

For reference, when the task project is not referenced in the app project, it builds without errors. Errors show up when it is.

@myokeeh
Copy link
Author

myokeeh commented May 16, 2023

Removing the Microsoft.Windows.CsWinRT reference on the background task allows it to build, but I suppose that breaks the background task. With the reference removed, I tried triggering the task, but does nothing (doesn't work) unlike the sample app (works).

@myokeeh
Copy link
Author

myokeeh commented May 16, 2023

I put back Microsoft.Windows.CsWinRT and found that at most, these are the ones I can keep refenced and the app builds, runs, and most importantly, the background task works.

Microsoft.Azure.Mobile.Client
Microsoft.Graph
Microsoft.Identity.Client.Broker

Adding the following is what causes the APPX1101 errors to come back:

CommunityToolkit.WinUI.Connectivity
CommunityToolkit.WinUI.Notifications
Microsoft.AppCenter.Analytics
Microsoft.AppCenter.Crashes

@myokeeh
Copy link
Author

myokeeh commented May 16, 2023

The fix is adding a Directory.Builds.target file with the following contents per microsoft/WindowsAppSDK#3390

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="CsWinRTAuthoring_AddManagedDependencies" />
</Project>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants