Referencing a Windows Metadata component directly when targeting .NET 5 or higher is not supported

Viewed 1168

I have a .Net5.0 C# class library project, it was building just fine, however after changing the target framework to <TargetFramework>net6.0</TargetFramework> the build starts failing with the following error messages:

C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.AI.MachineLearning.MachineLearningContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.AI.MachineLearning.Preview.MachineLearningPreviewContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Activation.ActivatedEventsContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Activation.ActivationCameraSettingsContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Activation.ContactActivatedEventsContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Activation.WebUISearchActivatedEventsContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Background.BackgroundAlarmApplicationContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Calls.Background.CallsBackgroundContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Calls.CallsPhoneContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Calls.CallsVoipContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Calls.LockScreenCallContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.CommunicationBlocking.CommunicationBlockingContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.FullTrustAppContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Preview.InkWorkspace.PreviewInkWorkspaceContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Preview.Notes.PreviewNotesContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Resources.Management.ResourceIndexerContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Search.Core.SearchCoreContract.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
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1003,5): error NETSDK1130: Windows.ApplicationModel.Search.SearchContract.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
...

Now even after reverting the configuration back to <TargetFramework>net5.0</TargetFramework> problem persists. Please note that I'm using Visual Studio 2019 with .Net6.0 SDK already installed. Here is the csproj file:

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

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Ben.Demystifier" Version="0.1.4" />
    <PackageReference Include="BundlerMinifier.Core" Version="3.2.449" />
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.6.1" />
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="2.1.1" />
    <PackageReference Include="Microsoft.Identity.Client" Version="4.30.1" />
    <PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="4.5.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
    <PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" />
    <PackageReference Include="Synergix.WE.ComputerManagement" Version="2.4.34" />
  </ItemGroup>

  <ItemGroup>

UPDATE:

The package <PackageReference Include="Synergix.WE.ComputerManagement" Version="2.4.34" /> is built using .netStandard2.1, when removing it from references the error is gone but ofcorse the build fails because of inner deppendencies, is it impossible to reference a .netStandard library in a .net6 project?

1 Answers

Solution:

1 - Set the TargetFramework to <TargetFramework>net6.0-windows$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</TargetFramework>

2 - Add a package reference to CsWinRT through <PackageReference Include="Microsoft.Windows.CsWinRT" Version="1.4.1" />

Related