microsoft / CsWinRT

C# language projection for the Windows Runtime
MIT License
546 stars 104 forks source link

CsWinRT should automatically reference the correct WinMD files when a native project and a managed projection project reference the same NuGet package #907

Open jlaanstra opened 3 years ago

jlaanstra commented 3 years ago

Proposal: CsWinRT should automatically reference the correct WinMD files when a native project and a managed projection project reference the same NuGet package

Summary

When a native project references a NuGet package that can be used in both native and .NET5 projects and uses types from this NuGet package, the .NET 5 projection project for this native project does not automatically reference the WinMDs from the NuGet package and therefore can't generate the projection. Custom MSBuild logic such as https://github.com/microsoft/CsWinRT/blob/92f671d2f6fffca6f4119f549a05225b6a0329a9/src/Projections/WinUI/WinUI.csproj#L43 is currently needed to make this work.

Rationale

Mixing native and managed projects should just work like it did before and there should not be a need to write custom MSBuild logic to make this work.

Important Notes

We should at a minimum document how to do this.

jlaanstra commented 3 years ago

787 seems related as it also attempts to use WinMDs from a NuGet that NuGet wouldn't include automatically.

Scottj1s commented 3 years ago

I like this enhancement. Note that generally, the CsWinRTInputs custom logic is not needed for explicitly added nuget packages. It's only Microsoft.WinUI that required this, as the comment explains: <!--Explicitly reference WinUI winmds from TFM uap10.0--> Some of this behavior might be improved with the migration of the cswinrt repo to Reunion.

jlaanstra commented 3 years ago

@Scottj1s Even if I explicitly add the Microsoft.ProjectReunion.WinUI to the projection project I still seem to need to explicitly add the WinMDs, so your statement doesn't seem correct.