microsoft / WindowsAppSDK

The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
https://docs.microsoft.com/windows/apps/windows-app-sdk/
MIT License
3.8k stars 320 forks source link

Winmd File Reference Issue: Multiple Publish Output Files with Same Relative Path #4764

Open Jack251970 opened 18 hours ago

Jack251970 commented 18 hours ago

Describe the bug

If you include winmd file in your project, like this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <RootNamespace>WinmdTest</RootNamespace>
    <UseWinUI>true</UseWinUI>
    <TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
    <CsWinRTIncludes>Microsoft.Windows.Widgets.Hosts</CsWinRTIncludes>
    <!-- ... other properties ... -->
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.4" />
    <!-- ... other packages ... -->
  </ItemGroup>

  <ItemGroup>
    <Content Include=".\BuildAssets\Microsoft.Windows.Widgets.Internal.winmd" Link="Microsoft.Windows.Widgets.Internal.winmd" CopyToOutputDirectory="PreserveNewest" />
    <Content Include=".\BuildAssets\Microsoft.Windows.Widgets.winmd" Link="Microsoft.Windows.Widgets.winmd" CopyToOutputDirectory="PreserveNewest" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="Microsoft.Windows.Widgets.Hosts">
      <HintPath>.\BuildAssets\Microsoft.Windows.Widgets.winmd</HintPath>
      <IsWinMDFile>true</IsWinMDFile>
    </Reference>
  </ItemGroup>

  <!-- ... other item groups and references ... -->
</Project>

and then it will give you the issue:

Severity    Code    Description Project File    Line    Suppression State   Details
Error (active)  NETSDK1152  Found multiple publish output files with the same relative path: D:\source\repos\WinmdTest\WinmdTest\BuildAssets\Microsoft.Windows.Widgets.winmd, D:\source\repos\WinmdTest\WinmdTest\obj\x64\Debug\net8.0-windows10.0.22621.0\MsixContent\Microsoft.Windows.Widgets.winmd. WinmdTest   C:\Program Files\dotnet\sdk\8.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ConflictResolution.targets 112     

Originally, I think this issue relates to msbuild. However when I downgrade the version of Microsoft.WindowsAppSDK, this issue just disappear. So I decide to report it here.

Sometimes, I can avoid the compile issue when changing CopyToOutputDirectory="PreserveNewest" to CopyToOutputDirectory="Never". But it causes Typename or Namespace was not found in metadata file. issue, and it seems the project has issues for loading the winmd files.

This issue will happen in Microsoft.WindowsAppSDK 1.5+ (1.5 included).

Steps to reproduce the bug

  1. Clone issue demo project: https://github.com/Jack251970/WinmdTest.
  2. Open WinmdTest.csproj file and change version in
    <!-- No Issue Using This Nuget Package. -->
    <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.240802001" />
    <!-- Issue Exists Using This Nuget Package. -->
    <!-- <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" /> -->
  3. Using the <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.240802001" />, the project can work well. But <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" /> cannot.

Expected behavior

No response

Screenshots

No response

NuGet package version

None

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 22H2 (22621, 2022 Update)

IDE

Visual Studio 2022

Additional context

No response