unoplatform / uno

Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
https://platform.uno
Apache License 2.0
8.51k stars 690 forks source link

`Uno.WinUI.MSAL` and `WindowsAppSDKSelfContained` clash #14555

Open MartinZikmund opened 6 months ago

MartinZikmund commented 6 months ago

Current behavior

After adding Uno.WinUI.MSAL and setting <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained> in Windows .csproj, build fails with:

C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ConflictResolution.targets(112,5): error NETSDK1152: Found multiple publish output files with the same relative path: C:\Dev\mzikmund\src\app\MZikmund.Windows\obj\x64\Debug\net8.0-windows10.0.19041.0\MsixContent\Microsoft.Web.WebView2.Core.dll, C:\Users\marti.nuget\packages\microsoft.web.webview2\1.0.864.35\lib\netcoreapp3.0\Microsoft.Web.WebView2.Core.dll.

Expected behavior

Should not fail build

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

No response

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

No response

Affected platforms

Windows

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

jeromelaban commented 6 months ago

Feels similar to https://github.com/microsoft/microsoft-ui-xaml/issues/8857

christianfo commented 5 months ago

I ran into the same problem. All it takes is to add a dependency on Microsoft.Identity.Client (Version 4.58.1) to the "shared" app project of an Uno sample app (from the Visual Studio templates). Then try to build and you get:

C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ConflictResolution.targets(112,5): error NETSDK1152: Found multiple publish output files with the same relative path: 
C:\uno\UnoApp13\UnoApp13\UnoApp13.Windows\obj\x86\Debug\net7.0-windows10.0.19041.0\win-x86\MsixContent\Microsoft.Web.WebView2.Core.dll, 
C:\Users\[username]\.nuget\packages\microsoft.web.webview2\1.0.864.35\lib\netcoreapp3.0\Microsoft.Web.WebView2.Core.dll.

Adding a reference to package Microsoft.Web.WebView2 (instead of Microsoft.Identity.Client) creates the same issue. Microsoft.Identity.Client depends on Microsoft.Web.WebView2 and brings it in. Microsoft.Web.WebView2 is the package that causes the "multiple publish output file" issue, apparently conflicting with a Microsoft.WebView2.Core.dll brought in by the MSIX packaging.

Adding a reference to package Uno.WinUI.MSAL also causes the same issue, as it depends on Microsoft.Identity.Client.

Adding a reference to either of these packages in a WinUI3 app works fine.

Note that this problem only affects the Windows build, not WASM or Android.

So far, I have not been able to make the workaround mentioned in 8857 work.

christianfo commented 5 months ago

Tried upgrading Uno packages from 5.0.118 to 5.1.0-dev.1108. That did not help.

christianfo commented 5 months ago

@jeromelaban, any pointer as to how to try to make a workaround?

baskren commented 5 months ago

@christianfo : Just a guess at a potential work around (at the moment I don't have the time to try this out) :

What about adding ExcludeAssets="all" to the <PackageReference Include="Uno.UI.MSAL" />, and then including <PackageReference Include="Uno.UI.MSAL" /> in the platform (Windows) project?

UPDATE : No, didn't work. Nor did going into the ~/.nuget/packages/microsoft.identity.client/4.58.1/microsoft.identity.client.nuspec and making the following edits:

      <group targetFramework="net6.0-windows7.0">
        <dependency id="Microsoft.Identity.Client.NativeInterop" version="0.13.14" exclude="Build,Analyzers" />
        <dependency id="Microsoft.IdentityModel.Abstractions" version="6.22.0" exclude="Build,Analyzers" />
        <!--<dependency id="Microsoft.Web.WebView2" version="1.0.864.35" exclude="Build,Analyzers" />-->
        <dependency id="System.Diagnostics.DiagnosticSource" version="7.0.2" exclude="Build,Analyzers" />
      </group>

... which I really hoped would work!

christianfo commented 5 months ago

Thank you very much, @baskren! With your proposed workaround, I get compilation errors everywhere I am referring to anything in Microsoft.Identity.Client or Uno.WinUI.MSAL (that code is in a "shared" project). I am toying with excluding only some of the assets, not all, but so far, no luck.

christianfo commented 5 months ago

@christianfo : Just a guess at a potential work around (at the moment I don't have the time to try this out) :

What about adding ExcludeAssets="all" to the <PackageReference Include="Uno.UI.MSAL" />, and then including <PackageReference Include="Uno.UI.MSAL" /> in the platform (Windows) project?

UPDATE : No, didn't work. Nor did going into the ~/.nuget/packages/microsoft.identity.client/4.58.1/microsoft.identity.client.nuspec and making the following edits:

      <group targetFramework="net6.0-windows7.0">
        <dependency id="Microsoft.Identity.Client.NativeInterop" version="0.13.14" exclude="Build,Analyzers" />
        <dependency id="Microsoft.IdentityModel.Abstractions" version="6.22.0" exclude="Build,Analyzers" />
        <!--<dependency id="Microsoft.Web.WebView2" version="1.0.864.35" exclude="Build,Analyzers" />-->
        <dependency id="System.Diagnostics.DiagnosticSource" version="7.0.2" exclude="Build,Analyzers" />
      </group>

... which I really hoped would work!

Thanks for trying this out! I tried something similar by excluding the same in the PackageReference of WebView2, but that did not work either. Note that I have an app that needs Uno.WinUI.MSAL, but another one where I need WebView2 as well. I have been trying to build a patch similar to what is in 8857, but to no avail so far.

baskren commented 5 months ago

MsalTest2.zip

@christianfo : Starting to see if I can get this work, I started with a new WinUI3 app template and flushed out MSAL support, Microsoft.Datasync.Client support, and then changes to the Window's platform project's .csproj to support net7.0 Release builds and net8.0. The result is attached, above. I'm going to repeat this process with a new Uno.WinUI template and see what's different.

christianfo commented 5 months ago

@baskren, thanks for doing these experiments! I have had the same experience. I have been able to make MSAL auth work via Microsoft.Identity.Client and also WebView2 using Microsoft.Web.WebView2 on new and existing WinUI3 projects. On Uno, I tried to add MSAL auth on an existing Uno app and a new app created from the VS templates. Both yielded the same "Found multiple publish output files with the same relative path" error.

christianfo commented 5 months ago

I have been trying to find the place in the build process (in particular the MSIX part of it) where I could prune out the duplicated WebView2 files that it is complaining about in a manner similar to the work around shown in 8857 but so far, I have not been successful.

christianfo commented 5 months ago

In case that is useful, here are the WinUI3 and Uno sample apps I was trying MSAL on. In each app, OneDrive.cs has very simple code to authenticate to OneDrive with an MSA. I have X'ed out the client id for security reasons. Replace by yours if you want to try this. Your app registration should support Microsoft Personal Account and use the default URL (first suggested).

WinUI3 app: App1.zip

Uno app (does not build for Windows, but builds for WASM and Android): UnoApp13.zip

baskren commented 5 months ago

@christianfo -

OK, I believe that I've figured it out. Here is what I learned:

  1. Adding aUno.WinUI.MSAL or Microsoft.Identity.Client nuget package to an Uno Platform app project works out of the box, using the most recent templates.
  2. Immediately after adding a Uno.WinUI.MSAL or Microsoft.Identity.Client nuget package to an Uno Library (using the most recent templates) VisualStudio 2022 (or dotnet restore) gives the following errors during the restore:
    error NETSDK1082: There was no runtime pack for Microsoft.WindowsDesktop.App.WindowsForms available for the specified RuntimeIdentifier 'win10-arm'
    error NETSDK1082: There was no runtime pack for Microsoft.WindowsDesktop.App.WindowsForms available for the specified RuntimeIdentifier 'win10-arm-aot'
  3. Since, in the Uno App, the cross-platform application project is (for all practical purposes) just a cross-platform library, what are the differences? Taking a closer look, I decided to add the following lines into the <When Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'"> block of the Uno Library project that used an MSAL nuget:
      <PropertyGroup>
        <!-- The following eliminated " error NETSDK1082: There was no runtime pack for Microsoft.WindowsDesktop.App.WindowsForms available for the specified RuntimeIdentifier 'win10-arm' / 'win10-arm-aot'." -->
        <RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
        <UseRidGraph>true</UseRidGraph>
        <UseWinUI>true</UseWinUI>
      </PropertyGroup>

    With those additional lines, the dotnet restore worked from the command line and VisualStudio 2022 was happy when loading the Uno Library project. Next, I was able to successfully build the Uno Library. Finally, I returned to my POC project, applied all of these changes, and was able to successfully build Debug/Release builds and successfully Package and Publish for x86, x64 and arm64!

UnoMsalApp2.zip

christianfo commented 5 months ago

@baskren, thank you! When I try to build the UnoMsalApp2 that you posted above, I still get the following error:

9>C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ConflictResolution.targets(112,5): error NETSDK1152: Found multiple publish output files with the same relative path: 
C:\uno\UnoMsalApp2\UnoMsalApp2\UnoMsalApp2.Windows\obj\x64\Debug\net8.0-windows10.0.19041.0\win-x64\MsixContent\Microsoft.Web.WebView2.Core.dll, 
C:\Users\chris.CHRISF103\.nuget\packages\microsoft.web.webview2\1.0.864.35\lib\netcoreapp3.0\Microsoft.Web.WebView2.Core.dll.

Since you are able to build on your machine, there must be something specific to my environment that is different. Maybe it has to do with the version(s) of WebView2 NuGet packages present on my machine. I will dig a bit further in that direction.

baskren commented 5 months ago

Both hypotheses sound mildly plausible.

Just out of curiosity, what happens when you start with a fresh dotnet new unoapp -o UnoMsalTest, add the following to the .csproj, and then try to build/run?

<ItemGroup>
    <PackageReference Include="Microsoft.Indentity.Client" Version="4.58.1" />
</ItemGroup>

Perhaps it is my environment (M2 MBP + Windows 11 ARM via Parallels). FWIW:

Visual Studio 2022 Info
System Info OS Name Microsoft Windows 11 Enterprise Version 10.0.22631 Build 22631 Other OS Description Not Available OS Manufacturer Microsoft Corporation System Name [my machine name here] System Manufacturer Parallels International GmbH. System Model Parallels ARM Virtual Machine System Type ARM64-based PC System SKU Parallels_ARM_VM Processor Apple Silicon, 3200 Mhz, 1 Core(s), 1 Logical Processor(s) Processor Apple Silicon, 3200 Mhz, 1 Core(s), 1 Logical Processor(s) Processor Apple Silicon, 3200 Mhz, 1 Core(s), 1 Logical Processor(s) Processor Apple Silicon, 3200 Mhz, 1 Core(s), 1 Logical Processor(s) Processor Apple Silicon, 3200 Mhz, 1 Core(s), 1 Logical Processor(s) Processor Apple Silicon, 3200 Mhz, 1 Core(s), 1 Logical Processor(s) BIOS Version/Date Parallels International GmbH. 19.2.1 (54832), Not Available SMBIOS Version 3.0 Embedded Controller Version 255.255 BIOS Mode UEFI BaseBoard Manufacturer Parallels ARM Virtual Machine BaseBoard Product Parallels ARM Virtual Platform BaseBoard Version 0.1 Platform Role Slate Secure Boot State On PCR7 Configuration Elevation Required to View Windows Directory C:\Windows System Directory C:\Windows\system32 Boot Device \Device\HarddiskVolume2 Locale United States Hardware Abstraction Layer Version = "10.0.22621.2506" User Name [my machine name here]\ben Time Zone US Mountain Standard Time Installed Physical Memory (RAM) 48.0 GB Total Physical Memory 40.0 GB Available Physical Memory 28.9 GB Total Virtual Memory 42.5 GB Available Virtual Memory 31.2 GB Page File Space 2.50 GB Page File C:\pagefile.sys Kernel DMA Protection Off Virtualization-based security Not enabled Windows Defender Application Control policy Enforced Windows Defender Application Control user mode policy Off Device Encryption Support Elevation Required to View A hypervisor has been detected. Features required for Hyper-V will not be displayed.
christianfo commented 5 months ago

@baskren, that indeed creates a project that builds, I can add the following in the project file:

    <PackageReference Include="Microsoft.Identity.Client" />
    <PackageReference Include="Uno.WinUI.MSAL" />

with their PackageVersion counterparts in Directory.Packages.props

    <PackageVersion Include="Microsoft.Identity.Client" Version="4.58.1" />
    <PackageVersion Include="Uno.WinUI.MSAL" Version="5.0.41"/>

However, as soon as I add my OneDrive.cs code that calls into Microsoft.Identity.Client and Uno.WinUI.MSAL, I get the same error again:

2>C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ConflictResolution.targets(112,5): error NETSDK1152: Found multiple publish output files with the same relative path: 
C:\uno\UnoMsalTest\UnoMsalTest.Windows\obj\x64\Debug\net7.0-windows10.0.19041.0\win-x64\MsixContent\Microsoft.Web.WebView2.Core.dll,
C:\Users\[username]\.nuget\packages\microsoft.web.webview2\1.0.864.35\lib\netcoreapp3.0\Microsoft.Web.WebView2.Core.dll.
baskren commented 5 months ago

Hmmm. This is a long shot but what happens if you remove the <PackageVersion Include="Microsoft.Identity.Client" Version="4.58.1" /> and just keep the <PackageVersion Include="Uno.WinUI.MSAL" Version="5.0.41"/>?

christianfo commented 5 months ago

No difference. Same error. Also, afaict, your VS and System infos are very similar to mine. I tried deleting the NuGet local caches on my machine, but that did not change anything either.

baskren commented 5 months ago

... and you've done a dotnet tool update -g uno.check and then command line run uno-check recently, too, I'm guessing?

christianfo commented 5 months ago

I had uno.check 1.17.0, just updated to 1.18.1 (latest), closed VS, reran uno-check, restarted VS, but getting same error.

christianfo commented 5 months ago

FWIW, here is the app you suggested I built: UnoMsalTest.zip

baskren commented 5 months ago

@christianfo :

OK, I think you're right in thinking it's something in your build environment. I just built the two apps you shared earlier and they both worked!

So, I only have one more suggestion. Spin up and new VM, install VisualStudio 2022, install the Uno Platform extension for VisualStudio, run uno-check, and try again. If that works, then it really is your machine's environment.

christianfo commented 5 months ago

Will do. I was also installing latest VS and Uno platform on another machine. Will let you know what I learn.

As a curiosity, could you tell me what Microsoft.Web.WebView2 package(s) you have on your machine. Given that the error appears to be complaining about the MSIX build and the app build trying to deploy the Microsoft.Web.WebView2.Core.dll file to the same location, I was thinking this might have to do with the state of the WebView2 packages on our respective machines.

baskren commented 5 months ago

Not sure if there's another system reference to WebView2 in the environment that wouldn't be controlled by the <PackageReference ... /> items we used in our .csproj files.

christianfo commented 5 months ago

Thanks, I have the same on my machine.

christianfo commented 5 months ago

I just finished installing on my second machine (laptop) and I am getting the same error.

christianfo commented 5 months ago

As a data point, if I disable MSIX Tooling:

<PropertyGroup>
  <EnableMsixTooling>false</EnableMsixTooling>
</PropertyGroup>

and build the Unpackaged target, it builds.

(My real app had dependencies on being a packaged app, so this is hardly a work around for me, but it does confirm this has something to do with the MSIX packaging part of the build)

baskren commented 5 months ago

Interesting. I thought I was building for packaged. I’ll have to confirm if I was or not. I know I “Packaged and publish” as MSIX to test if it worked.

I’ll take a closer look at all this tomorrow.

baskren commented 5 months ago

One more thing. Do you have the Visual Studio “MSIX packaging extension” installed?

christianfo commented 5 months ago

I have the "Single-project MSIX Packaging Tools for VS 2022" installed.

baskren commented 5 months ago

I was able to confirm that I was using "packaged" app builds and that I was able to generate MSIX files.

christianfo commented 5 months ago

Thanks @baskren and happy New Year!

christianfo commented 5 months ago

I still don't understand why this fails for me and works on @baskren's machine, but I managed to create a patch to work around the problem and build and run successfully. Sharing in case this is useful to others. Just add the following to your windows project:

<!--
  This is a temporary workaround to avoid error "NETSDK1152: Found multiple publish output files with the same relative path:"
  for Microsoft.Web.WebView2.Core.dll, with one coming from MsixContent and the other from the Microsoft.Web.Webview2 Nuget package.
  If both are present, we only keep the one from the NuGet package. See https://github.com/unoplatform/uno/issues/14555.
-->
<Target Name="ResolveWebView2CoreDuplicates1" BeforeTargets="_ComputeResolvedFilesToPublishTypes" AfterTargets="ComputeFilesToPublish">
  <Message Importance="high" Text ="Applying workaround to resolve Microsoft.Web.WebView2.Core.dll duplication in package (1)" />
  <ItemGroup>
    <_WebView2CoreFilesToExclude Include="@(ResolvedFileToPublish)" Condition="'%(Filename)' == 'Microsoft.Web.WebView2.Core'"/>
  </ItemGroup>
  <ItemGroup Condition="'@(_WebView2CoreFilesToExclude->Count())' &gt; 1">
    <_WebView2CoreFilesToExclude Remove="@(_WebView2CoreFilesToExclude)" Condition="$([System.String]::Copy(%(FullPath)).Contains('.nuget'))"/>
    <ResolvedFileToPublish Remove="@(_WebView2CoreFilesToExclude)" />
  </ItemGroup>
  <Message Importance="high" Text ="Removed: @(_WebView2CoreFilesToExclude)" />
</Target>

<Target Name="ResolveWebView2CoreDuplicates2" BeforeTargets="_ComputeAppxPackagePayload" AfterTargets="GetPackagingOutputs">
  <Message Importance="high" Text ="Applying workaround to resolve Microsoft.Web.WebView2.Core.dll duplication in package (2)" />
  <ItemGroup >
    <_WebView2CoreOutputsToExclude Include="@(PackagingOutputs)" Condition="'%(Filename)' == 'Microsoft.Web.WebView2.Core'"/>
  </ItemGroup>
  <ItemGroup Condition="'@(_WebView2CoreOutputsToExclude->Count())' &gt; 1">
    <_WebView2CoreOutputsToExclude Remove="@(_WebView2CoreOutputsToExclude)" Condition="$([System.String]::Copy(%(FullPath)).Contains('.nuget'))"/>
    <PackagingOutputs Remove="@(_WebView2CoreOutputsToExclude)" />
  </ItemGroup>
  <Message Importance="high" Text ="Removed: @(_WebView2CoreOutputsToExclude)" />
</Target>
baskren commented 5 months ago

@christianfo : WOW! Based upon the content of your work around, you must have really put in some time. Thank you! Next week I am going to be working on a new project that requires developing from a Windows 10 laptop. In that past I know I had this issue on that device and haven't had a chance to see if it's still present. I'm guessing that you might have just made my life a lot easier next week!

christianfo commented 5 months ago

@baskren, yes it took me a little while :). But it's nice to be able to get past this! Definitely let me know if this works for you!

jeromelaban commented 5 months ago

@christianfo the workaround is indeed working properly, thanks! I'm not sure where this workaround should live, and what the cause of this is. This feels like Microsoft.Web.WebView2.Core should be fixed and that an issue will need to be opened there, but there's no github repo for it. We'll follow up with the WinUI team.

christianfo commented 5 months ago

@jeromelaban, yes, this is likely something for the WinUI or the Edge team to fix. Let me know if I can help follow up with them. This is definitely only a temporary workaround. Future changes in the WinUI3 build system could easily break it.

christianfo commented 3 months ago

I tried to upgrade to Windows App SDK 1.5.240205001-preview1 and I am getting another similar conflict now:

5>C:\Users\[username]\.nuget\packages\microsoft.windowsappsdk\1.5.240205001-preview1\buildTransitive\Microsoft.Build.Msix.Packaging.targets(1515,5): error APPX1101: Payload contains two or more files with the same destination path 'Microsoft.WindowsAppRuntime.Bootstrap.dll'. Source files: 
5>C:\Users\[username]\.nuget\packages\microsoft.windowsappsdk\1.5.240205001-preview1\buildTransitive\Microsoft.Build.Msix.Packaging.targets(1515,5): error APPX1101: C:\Users\[username]\.nuget\packages\microsoft.windowsappsdk\1.5.240205001-preview1\runtimes\win10-x86\native\Microsoft.WindowsAppRuntime.Bootstrap.dll
5>C:\Users\chris.CHRISF103\.nuget\packages\microsoft.windowsappsdk\1.5.240205001-preview1\buildTransitive\Microsoft.Build.Msix.Packaging.targets(1515,5): error APPX1101: C:\uno\eHouse3\MainApp\MainApp.Windows\obj\x86\Debug\net7.0-windows10.0.19041.0\win10-x86\MsixContent\Microsoft.WindowsAppRuntime.Bootstrap.dll       

Probably time to augment the workaround...

jeromelaban commented 3 months ago

@christianfo for that particular error, you may try removing the workaround, as https://github.com/microsoft/microsoft-ui-xaml/issues/8857 got fixed.

baskren commented 3 months ago

@christianfo : FWIW, after my virgin project got complicated, this problem appeared. Your work around worked!

LeonSpors commented 2 months ago

The workaround used to be effective previously. However, ever since we upgraded WinAppSDK to version 1.5.X, it no longer functions properly for publishing.

jeromelaban commented 1 month ago

As an update, https://github.com/microsoft/WindowsAppSDK/issues/4249 is being tracked to resolve this issue. Uno has a workaround integrated when referencing Uno.Extensions.Authentication.MSAL (from https://github.com/unoplatform/uno.extensions/pull/2205). The workaround here https://github.com/unoplatform/uno/issues/14555#issuecomment-1876175425 is still applicable for WinAppSDK 1.5.240404000.

ancker1 commented 1 month ago

I have found a workaround that made my project work here:

https://github.com/microsoft/microsoft-ui-xaml/issues/5689#issuecomment-1987601754

ancker1 commented 1 month ago

I have found a workaround that made my project work here:

microsoft/microsoft-ui-xaml#5689 (comment)

For those still experiencing an error: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/3583#issuecomment-2092606633

ciarancolgan commented 2 weeks ago

I still don't understand why this fails for me and works on @baskren's machine, but I managed to create a patch to work around the problem and build and run successfully. Sharing in case this is useful to others. Just add the following to your windows project:

<!--
  This is a temporary workaround to avoid error "NETSDK1152: Found multiple publish output files with the same relative path:"
  for Microsoft.Web.WebView2.Core.dll, with one coming from MsixContent and the other from the Microsoft.Web.Webview2 Nuget package.
  If both are present, we only keep the one from the NuGet package. See https://github.com/unoplatform/uno/issues/14555.
-->
<Target Name="ResolveWebView2CoreDuplicates1" BeforeTargets="_ComputeResolvedFilesToPublishTypes" AfterTargets="ComputeFilesToPublish">
  <Message Importance="high" Text ="Applying workaround to resolve Microsoft.Web.WebView2.Core.dll duplication in package (1)" />
  <ItemGroup>
    <_WebView2CoreFilesToExclude Include="@(ResolvedFileToPublish)" Condition="'%(Filename)' == 'Microsoft.Web.WebView2.Core'"/>
  </ItemGroup>
  <ItemGroup Condition="'@(_WebView2CoreFilesToExclude->Count())' &gt; 1">
    <_WebView2CoreFilesToExclude Remove="@(_WebView2CoreFilesToExclude)" Condition="$([System.String]::Copy(%(FullPath)).Contains('.nuget'))"/>
    <ResolvedFileToPublish Remove="@(_WebView2CoreFilesToExclude)" />
  </ItemGroup>
  <Message Importance="high" Text ="Removed: @(_WebView2CoreFilesToExclude)" />
</Target>

<Target Name="ResolveWebView2CoreDuplicates2" BeforeTargets="_ComputeAppxPackagePayload" AfterTargets="GetPackagingOutputs">
  <Message Importance="high" Text ="Applying workaround to resolve Microsoft.Web.WebView2.Core.dll duplication in package (2)" />
  <ItemGroup >
    <_WebView2CoreOutputsToExclude Include="@(PackagingOutputs)" Condition="'%(Filename)' == 'Microsoft.Web.WebView2.Core'"/>
  </ItemGroup>
  <ItemGroup Condition="'@(_WebView2CoreOutputsToExclude->Count())' &gt; 1">
    <_WebView2CoreOutputsToExclude Remove="@(_WebView2CoreOutputsToExclude)" Condition="$([System.String]::Copy(%(FullPath)).Contains('.nuget'))"/>
    <PackagingOutputs Remove="@(_WebView2CoreOutputsToExclude)" />
  </ItemGroup>
  <Message Importance="high" Text ="Removed: @(_WebView2CoreOutputsToExclude)" />
</Target>

Thank you for this @christianfo! Saved us a lot of hassle. Can i also echo the disappointment of others that this issue has been open so long both here and in its other various guises: