Compilation fails with NETSDK1130 error, WITHOUT directly referencing a winmd
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
A binlog could confirm if/where a winmd reference is sneaking in. But ultimately, this enforcement needs to be reconsidered, and winmd references treated as benign (especially if it can be proved that they aren't consumed by csc)
See also: https://github.com/dotnet/sdk/issues/12087 https://github.com/dotnet/sdk/issues/13233
@Scottj1s , Thanks for your reply.
The mentioned test-solution is very small and simple, and to me it seems clear what sneaks them in.
Microsoft.Toolkit.Uwp.Notifications depends on microsoft.windows.sdk.contracts and that one references dozens of winmd's.
The point is: they are not referenced 'directly' by the projects. They are dragged in by other nuget packages and then it's pretty much out of the developers' control, especially if you really need certain functionality.
Your comment about reconsidering the enforcement gives me hope, because if this enforcement is not relaxed it probably means a set back of several weeks because it means I have to find a solution for not being able to use essential nuget packages which literally were no problem last week.
@Scottj1s these would fail at runtime in 5.0 so the package needs to be updated rather than us relaxing the enforcement here. Please contact the owners of https://github.com/windows-toolkit/WindowsCommunityToolkit to get a 5.0 package updated without the winmd references as the direct references aren't needed anymore in net5.0-windows targeting.
@marcpopMSFT, a runtime error would result only if types were actually referenced from a winmd supplied to csc.exe, which is why I've suggested that such references should be benign, unless such types are referenced. Otherwise, the enforcement is very difficult for third parties to track down and implement.
Repro project, for reference: https://github.com/Scottj1s/NETSDK1130
@dsplaisted to respond in email on the discussion we're having on this.
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.
Why nobody fixing this issue? I lost so much time and still can't find workaround.