CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

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

Open jlaanstra opened this issue 2 years ago • 3 comments

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 avatar Jul 12 '21 16:07 jlaanstra

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

jlaanstra avatar Jul 12 '21 17:07 jlaanstra

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.

Scottj1s avatar Jul 12 '21 17:07 Scottj1s

@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.

jlaanstra avatar Jul 12 '21 17:07 jlaanstra