ModernWpf: Build Error on .NET 5

After upgrading from .NET 5 preview 7 to .NET 5 RC 2 I’m getting this error on project build: Microsoft.NET.Sdk.targets(934, 5): [NETSDK1130] Referencing a Windows Metadata component directly when targeting .NETCoreApp,Version=v5.0 is not supported. Use the C#/WinRT projection tool (https://aka.ms/cswinrt) or a provided projection for this target. To reproduce: Create WPF app using .NET 5, install newest version of ModernWpfUI (I’m getting error on older versions too), run build. Thanks in advance!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 16 (5 by maintainers)

Commits related to this issue

Most upvoted comments

@rfloresarg just change targetframework to this: net5.0-windows10.0.18362.0

The project needs to target net5.0-windows10.0.18362.0 or higher, since this library calls WinRT APIs. You can find related documentation here. The app will still be able to run on older versions of Windows.

just change targetframework to this: net5.0-windows10.0.18362.0 or newer

Can reproduce, this fixes everything for me. Thanks for the fix! It’s quite important for me to use the non-forked Nuget versions.

Thanks, @ShankarBUS @ghost1372 ! I haven’t used OS versions in target framework monikers before, so I misunderstood what it means. I’ll test this on an older OS when I can, but there should be no issues. Here’s a relevant doc for someone who might misunderstand it as I did: https://docs.microsoft.com/en-us/dotnet/standard/frameworks#os-version-in-tfms

I’m using proper target framework name and latest preview. It’s because of that Nuget package.

Isn’t it possible to swap from WinRT to WinSDK? With net6.0-windows10.0.18362.0 I run into

error NETSDK1095: Optimizing assemblies for performance is not supported for the selected target platform or architecture. Please verify you are using a supported runtime identifier, or set the PublishReadyToRun property to false.

@skel35,

It’s just the target SDK!

It will work older Windows versions!

Try it out yourself 🙃.

After targeting net5.0-windows10.0.18362.0 as you’ve said earlier throw another error:

Referencing a Windows Metadata component directly when targeting .NETCoreApp,Version=v5.0 is not supported. Use the C#/WinRT projection tool (https://aka.ms/cswinrt) or a provided projection for this target.

Based on this issue stated that

We should update the error message (or perhaps just the link pointed at by https://aka.ms/cswinrt) to make it clear that the fix is to reference the Microsoft.Windows.CsWinRT NuGet package.

and after adding the references, there are some conflict like.

The type ‘Color’ exists in both ‘Microsoft.Windows.SDK.NET, Version=10.0.18362.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ and ‘System.Runtime.WindowsRuntime, Version=4.0.14.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’

Edit:

It’s working, I just explicitly referenced Windows.UI.Color (as for my cases)