Редагувати

Поділитися через


NETSDK1130: Can't reference a Windows Metadata component directly

NETSDK1130 indicates that you're trying to reference a Windows Metadata component directly from an app that targets .NET 5 or later. The full error message is similar to the following example:

<Component name> cannot be referenced. Referencing a Windows Metadata component directly when targeting .NET 5 or higher is not supported.

To resolve this error:

  • Remove references to the Microsoft.Windows.SDK.Contracts package. Instead, specify the version of the Windows APIs that you want to access via the TargetFramework property of the project. For example:

    <TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
    
  • If you're consuming a third-party runtime component that's defined in a .winmd file, add a reference to the Microsoft.Windows.CsWinRT NuGet package. For information on how to generate the C# projection, see the C#/WinRT documentation.

For more information, see Built-in support for WinRT is removed from .NET and Call Windows Runtime APIs in desktop apps.