question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compilation fails with NETSDK1130 error, WITHOUT directly referencing a winmd

See original GitHub issue

Hi,

I’m running into problems with NETSDK1130. Basically I can’t compile 84 of the 100 projects in my solution because of this error. The message seems very clear: 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. But that is exactly what I’m doing. I don’t have direct references to winmd files.

So, I created a small test solution comprising of 1 class library and 1 console app. These are the project files:

ClassLibrary

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0-windows</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="6.1.1" />
    <PackageReference Include="Microsoft.Windows.CsWinRT" Version="1.0.1" />
  </ItemGroup>

</Project>

Console app

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\ClassLibrary\ClassLibrary.csproj" />
  </ItemGroup>

</Project>

Both the class library and the console app contain only the newly scaffolded files (so, without any code).

Now when I try building the solution I get this output:

1>------ Rebuild All started: Project: ClassLibrary, Configuration: Debug Any CPU ------
2>------ Rebuild All started: Project: TestWinmd, Configuration: Debug Any CPU ------
2>C:\Program Files\dotnet\sdk\5.0.100-rc.2.20479.15\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(934,5):
    error 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.
2>Done building project "TestWinmd.csproj" -- FAILED.
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========

As you can see the ClassLibrary compiles fine and the console app fails.

My conclusion: there are no direct references to Windows Metadata components, therefore the NETSDK1130 error is misplaced.

As far as I can tell this problem started after upgrading nuget packages from .Net 5 RC1 to .Net 5 RC2. The copy of my dev-environment running the .Net 5 RC1 packages, compiles the entire solution just fine.

I’m using .Net 5.0 RC2, and Visual Studio Professional 2019 Version 16.8.0 Preview 5.0

I hope you can point out what I’m doing wrong here, because I have no clue on how to fix this, other that staying on .NET5 RC1.

Thanks, Richard

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ClosetBugSlayercommented, Jan 26, 2021

I’m having the same exact problem as OP. I regret ever attempting to port my project to .NET 5. I’m going to lose weeks too aren’t I. ($$$) I have to warn the others.

0reactions
marcpopMSFTcommented, Jan 6, 2021

@dsplaisted to respond in email on the discussion we’re having on this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NETSDK1130: Can't reference a Windows Metadata ...
In this article. NETSDK1130 indicates that you're trying to reference a Windows Metadata component directly from an app that targets .
Read more >
c# - Referencing a Windows Metadata component directly ...
NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Calls.CallsVoipContract.winmd cannot be referenced. Referencing a Windows ...
Read more >
Can't compile a .NET project that references UWP APIs if ...
NET projects with ClickOnce enabled and with a reference to the Windows.md library can't be compiled in Visual Studio 2017 due to an...
Read more >
Microsoft.NET.Sdk WPF .net6 errors when using ...
MachineLearningContract.winmd cannot be referenced. Referencing a Windows Metadata component directly when targeting .NET 5 or higher is not ...
Read more >
https://raw.githubusercontent.com/microsoft/CsWinR...
Move winmd references into private item group to prevent subsequent winmd reference errors--> <CsWinRTRemovedReferences Include="@(ReferencePath)" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found