CsWinRT
CsWinRT copied to clipboard
Referencing a Windows Metadata(.winmd) component in .NET 6
Hi Team,
I am using below api in .Net Framework based project ( Centennial app ).
Windows.UI.Core.Preview.Communications.PreviewTeamDeviceCredentials
have added a .winmd reference for this. This api mainly used in Windows Teams OS ( specially meant for Surface Hub devices).
While migrating to .NET 6.0 I started facing below issue -
Windows.UI.Core.Preview.Communications.PreviewCommunicationsContract.winmd
dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1027,5): error NETSDK1130:
Windows.UI.Core.Preview.Communications.PreviewCommunicationsContract.winmd cannot be referenced.
Referencing a Windows Metadata component directly when targeting .NET 5 or higher is not supported.
For more information, see https://aka.ms/netsdk1130
This api(Windows.UI.Core.Preview.Communications.PreviewTeamDeviceCredentials) is available as
| Device family | Windows Team Extension SDK (introduced in 10.0.19041.0) |
|---|---|
| API contract | Windows.UI.Core.Preview.Communications.PreviewCommunicationsContract (introduced in v1.0) |
In new project .NET 6.0 TFM is set to
<TargetFramework>net6.0-windows10.0.19041</TargetFramework>
I tried to follow the link https://aka.ms/netsdk1130 but couldn't figure out what needs to be done and seems to be stuck.
can someone please help here?
Is there any sample available which I can refer?
Right, you can't directly reference the winmd. I think you need to project that type (PreviewTeamDeviceCredentials) to use it, like this
I am able remove errors with below changes, is this the correct way? lib is folder where I have stored winmd file within project root.
<PropertyGroup>
<CsWinRTIncludes>Windows.UI.Core.Preview.Communications</CsWinRTIncludes>
</PropertyGroup>
<ItemGroup>
<!--Explicitly reference WinAppSDK winmds from TFM uap10.0-->
<CsWinRTInputs Include="lib\*.winmd" />
</ItemGroup>
Please review @j0shuams. Thanks
Did you install C#/WinRT?
yes @dongle-the-gadget, I did
Debug is running fine but during release build getting this error @j0shuams, @dongle-the-gadget -
The type or namespace name 'Communications' does not exist in the namespace 'Windows.UI.Core.Preview' (are you missing an assembly reference?)
@techyrajeev I'm surprised this is not working on release. Check your VS build configuration and for each permutation (Debug|x64, Release|x64, Debug|x86, etc...) make sure things are matching up.
If that's not it, feel free to attach a binlog.
@j0shuams do I need to create a separate project with winmd file and generate its projection and reference the nuget in my current project? Currently I directly added
<PropertyGroup> <CsWinRTIncludes>Windows.UI.Core.Preview.Communications</CsWinRTIncludes> </PropertyGroup> <ItemGroup> <!--Explicitly reference WinAppSDK winmds from TFM uap10.0--> <CsWinRTInputs Include="lib\*.winmd" /> </ItemGroup>
in main csproj file.
Please let me know if this is incorrect way to use cswinrt.
That is the correct way to generate a projection, you don't have to make a separate projection.
so, the issue comes only during publishing (when generating appxbundle via visual studio) in release mode. When I run the program directly form Visual Studio it works fine both in release mode and debug mode.
That is strange, could you attach a binlog?
I'm also trying to reference Windows.winmd in .Net 6, but can't get it to work. Any suggestions? I've installed CsWinRT.
C#/WinRT excludes Windows by default.