How to harvest CsWinRT projection WinMD files in single-project NET8 app for ActivatableClass
What's the recommended way of automatically harvesting the WinRT definitions from NuGet referenced WinMD files.
Current situation:
I have several NuGet packages that provide - for .net8 - a CsWinRT projection. This has a lib/net8.0-windows10/Component.Projection.dll.
In that NuGet package for uap10 and netstandard2.0 support I included the WinMD file as a copy.
On .NET8 I have a targets file with ItemGroup <CsWinRTInclude Include="..\..\lib\netstandard2.0\Component.winmd" />.
As this is not part of either the <Reference>-group, nor available anywhere else, what's the intended way to consume a CsWinRT projection library, while not having to manually include all ActivatableClass-definitions in the AppX manifest?
I tried with
<ItemGroup>
<WinMDFullPath Include="..\..\netstandard2.0\Component.winmd" />
</ItemGroup>
But that doesn't work.
@manodasanW can you investigate, or move this Issue to the appropriate repo for discussion (https://github.com/microsoft/CsWinRT).
additional info: As a workaround I am setting CsWinRTInputs for CsWinRT, and statically adding the WinMD through a ReferenceCopyLocalPaths-item (including Implementation-metadata), so the WinMD isn’t swallowed by CsWinRT and copied to the OutputDirectory, as CsWinRT eliminates these as well (which completely invalidates stuff like winrt::create_instance, will add more details here later), this item also results in WindowsAppSdk harvesting the WinMD and creating necessary Package-manifest entries. Which isn’t ideal.
CsWinRTInputs isn't the correct way to do this. That property is from CsWinRT, and it specifies which .winmd-s you want to be passed to cswinrt.exe to generate projections. The property you want here is WindowsMetadataReference, which is from the MSIX tooling (you can see an example of it being used by Win2D here). The recommendation is for NuGet packages shipping .winmd-s to include this property in a .targets file in \buildTransitive, so things "just work".
Note: for this to work you need the MSIX tooling version 1.3 or above. If you're using WinAppSDK, that means you need 1.8 preview or above. If you're using UWP .NET 9, you're good to go. Same if you're manually referencing just the MSIX tooling package from a standalone console, WinForms, WPF, etc. app.
Thank you for coming back to this, will give it a try later.
Confirmed, removing AppSdk 1.6, and instead using MSIX BuildTools 1.7 the AppxManifest is successfully harvested into the AppX with WindowsMetadataReference.