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

CS8785 when adding a locally built copy of Windows.Win32.winmd #1176

Closed
riverar opened this issue May 10, 2024 · 4 comments · Fixed by #1177
Closed

CS8785 when adding a locally built copy of Windows.Win32.winmd #1176

riverar opened this issue May 10, 2024 · 4 comments · Fixed by #1177
Labels
bug Something isn't working

Comments

@riverar
Copy link

riverar commented May 10, 2024

Actual behavior

After adding a reference to a custom projection metadata winmd, the source generator fails with the following warning:

CSC : warning CS8785: Generator 'SourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'An element with the same key but a different value already exists. Key: 'Windows.Win32'
<ItemGroup>
    <PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
        <PrivateAssets>all</PrivateAssets>
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <ProjectionMetadataWinmd Include="C:\Sources\win32metadata\bin\Windows.Win32.winmd" />
</ItemGroup>

Expected behavior

No warning / source generation to function

Repro steps

  1. Create a new baseline CsWin32-enabled C# project
  2. Attempt to refer to a custom .winmd on disk
  3. Observe warning/error

Context

  • CsWin32 version: 0.3.49-beta
  • Win32Metadata version (if explicitly set by project): N/A
  • Target Framework: net6.0
  • LangVersion (if explicitly set by project): N/A
@riverar riverar added the bug Something isn't working label May 10, 2024
@riverar
Copy link
Author

riverar commented May 10, 2024

Looks like I can cheat and use <CsWin32InputMetadataPaths> instead https://github.com/microsoft/CsWin32/blob/main/src/Microsoft.Windows.CsWin32/build/Microsoft.Windows.CsWin32.props#L22, but figured I'd run this past you.

@AArnott
Copy link
Member

AArnott commented May 10, 2024

Updating the win32metadata projection is typically done with a PackageReference, which will then override the one brought in by the cswin32 dependency. But if you really want to bring in your locally built one directly, you can add a PackageReference to the public win32metadata package with ExcludeAssets="build" to turn off its self-advertising, so you only have one win32metadata projection being proffered into cswin32.

@AArnott AArnott changed the title CS8785 when using custom projection metadata winmd CS8785 when adding a locally built copy of Windows.Win32.winmd May 10, 2024
@riverar
Copy link
Author

riverar commented May 10, 2024

Thanks @AArnott. Feel free to close if this is out of scope.

@AArnott
Copy link
Member

AArnott commented May 10, 2024

I think I'll improve the error reporting for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants