Open MartinZikmund opened 6 months ago
Feels similar to https://github.com/microsoft/microsoft-ui-xaml/issues/8857
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.
Tried upgrading Uno packages from 5.0.118 to 5.1.0-dev.1108. That did not help.
@jeromelaban, any pointer as to how to try to make a workaround?
@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!
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 : 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.
@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.
@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.
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.
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
@christianfo -
OK, I believe that I've figured it out. Here is what I learned:
Uno.WinUI.MSAL
or Microsoft.Identity.Client
nuget package to an Uno Platform app project works out of the box, using the most recent templates.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'
<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!
@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.
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:
@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.
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"/>
?
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.
... and you've done a dotnet tool update -g uno.check
and then command line run uno-check
recently, too, I'm guessing?
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.
FWIW, here is the app you suggested I built: UnoMsalTest.zip
@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.
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.
~/.nuget/Packages/microsoft.web.webview2/
folder, I only have the 1.0.864.35
folder.C:\Program Files (x86)\Microsoft SDKs\NuGetPackages
, I don't have a microsoft.web.webview2
folderNot 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.
Thanks, I have the same on my machine.
I just finished installing on my second machine (laptop) and I am getting the same error.
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)
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.
One more thing. Do you have the Visual Studio “MSIX packaging extension” installed?
I have the "Single-project MSIX Packaging Tools for VS 2022" installed.
I was able to confirm that I was using "packaged" app builds and that I was able to generate MSIX files.
Thanks @baskren and happy New Year!
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())' > 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())' > 1">
<_WebView2CoreOutputsToExclude Remove="@(_WebView2CoreOutputsToExclude)" Condition="$([System.String]::Copy(%(FullPath)).Contains('.nuget'))"/>
<PackagingOutputs Remove="@(_WebView2CoreOutputsToExclude)" />
</ItemGroup>
<Message Importance="high" Text ="Removed: @(_WebView2CoreOutputsToExclude)" />
</Target>
@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!
@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!
@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.
@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.
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...
@christianfo for that particular error, you may try removing the workaround, as https://github.com/microsoft/microsoft-ui-xaml/issues/8857 got fixed.
@christianfo : FWIW, after my virgin project got complicated, this problem appeared. Your work around worked!
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.
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.
I have found a workaround that made my project work here:
https://github.com/microsoft/microsoft-ui-xaml/issues/5689#issuecomment-1987601754
I have found a workaround that made my project work here:
For those still experiencing an error: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/3583#issuecomment-2092606633
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())' > 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())' > 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:
Current behavior
After adding
Uno.WinUI.MSAL
and setting<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
in Windows.csproj
, build fails with: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