WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

`dotnet publish` results in an error about duplicate files

Open mattleibow opened this issue 2 years ago • 4 comments

Issue moved from microsoft/microsoft-ui-xaml#7845

Describe the bug

Based on this issue: https://github.com/dotnet/maui/issues/9879

Passing a -r win10-x64 to a app .csproj tries to load both a "neutral" and a "RID-specific" dll/pdb into the app:

dotnet publish MyApp.csproj -c Release -f net6.0-windows10.0.19041.0 -r win10-x64

Steps to reproduce the bug

  1. Clone https://github.com/mattleibow/Maui-Issue-9879
  2. Execute the publish command:
    dotnet publish -r win10-x64 -f net6.0-windows10.0.19041.0 /bl .\WinUIApp\WinUIApp.csproj
    
  3. Observe error:
    Failure: msbuild.binlog.zip
    error APPX1101: Payload contains two or more files with the same destination path 'MauiClassLibrary.pdb'. Source files:
    error APPX1101: ...\MauiClassLibrary\bin\Release\net6.0-windows10.0.19041.0\MauiClassLibrary.pdb 
    error APPX1101: ...\MauiClassLibrary\bin\Release\net6.0-windows10.0.19041.0\win10-x64\MauiClassLibrary.pdb 
    
  4. Run build again with custom RuntimeIdentifierOverride property set:
     dotnet publish  .\WinUIApp\WinUIApp.csproj -c Release -f net6.0-windows10.0.19041.0 /p:RuntimeIdentifierOverride=win10-x86
    
  5. Observe success
    Success: msbuild.binlog.zip

Expected behavior

Passing the RID should only apply the the app project, and the class library references should just be non-RID.

Screenshots

No response

NuGet package version

1.1.4

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 21H2 (22000)

IDE

Other

Additional context

I was able to make a workaround:

Add this to the bottom of the app .csproj:

<PropertyGroup Condition="'$(RuntimeIdentifierOverride)' != ''">
	<RuntimeIdentifier>$(RuntimeIdentifierOverride)</RuntimeIdentifier>
</PropertyGroup>

Then when executing, use the new property instead of the RID:

dotnet publish  .\WinUIApp\WinUIApp.csproj -c Release -f net6.0-windows10.0.19041.0 /p:RuntimeIdentifierOverride=win10-x86

mattleibow avatar Jan 13 '23 22:01 mattleibow

It also seems that an error occurrs when PublishTrimmed set to true:

error APPX1101: Payload contains two or more files with the same destination path 'MauiApp1.pdb'. Source files:
error APPX1101: C:\Users\lopi2\source\repos\MauiApp1\MauiApp1\obj\Release\net7.0-windows10.0.19041.0\win10-x64\linked\MauiApp1.pdb
error APPX1101: C:\Users\lopi2\source\repos\MauiApp1\MauiApp1\bin\Release\net7.0-windows10.0.19041.0\win10-x64\MauiApp1.pdb

mattleibow avatar Sep 06 '23 20:09 mattleibow

Any workaround for this? I tried making PublishTrimmed set to false but nothing solved the problem Is this going to be solved when .NET 8 is released?

HakamFostok avatar Sep 28 '23 18:09 HakamFostok

Has no effect.

  <PropertyGroup>
    <PublishTrimmed>false</PublishTrimmed>
  </PropertyGroup>

sigmarsson avatar Sep 30 '23 15:09 sigmarsson

Related to https://github.com/microsoft/WindowsAppSDK/issues/4008

mattleibow avatar Nov 30 '23 22:11 mattleibow

@mattleibow So the fundamental issue is that the -r switch causes the passed in RID to be set as the global property RuntimeIdentifier and that simply isn't something we've ever handled well in conjunction with project references. This is why in both our project templates and our documentation we promote the use of publish profiles (Properties\*.pubxml in the app project). Your RuntimeIdentifierOverride property workaround is effectively emulating (part of) what our default publish profile does by setting the RuntimeIdentifier property for only the app project.

As a sidenote, dotnet publish should be run against the solution, rather than the app project, as this ensures that project references are built with the correct configuration/platform.

If I recreate your repro solution using our project templates (and updated to the latest internal WinAppSDK 1.6 build) such that the only meaningful difference is the addition of publish profiles, then the following works as expected and without issue: dotnet publish App4.sln.

evelynwu-msft avatar Aug 01 '24 02:08 evelynwu-msft