當 NETSDK1032 為 RuntimeIdentifier(RID)與 PlatformTarget不相符時,例如 win-x64 或 linux-x64與 x64 或 x86時,就會發生錯誤。 完整的錯誤訊息類似下列範例:
RuntimeIdentifier平臺 '{RID}' 和PlatformTarget'{Target}' 必須相容。
RID 是在項目檔或命令列中指定。 如果未指定,則預設的 RID 為 Windows 使用的是 win-x64,Linux 使用的是 linux-x64,macOS 使用的是 osx-x64。
PlatformTarget 是在項目檔或命令行中指定。 如果未指定,則預設值為 AnyCPU。
以下是具有不相容 RID 和 PlatformTarget 設定的 .csproj 檔案範例:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<PlatformTarget>x86</PlatformTarget>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
</Project>
藉由變更 PlatformTarget 或 RuntimeIdentifier來修正上述 .csproj 檔案。 例如,變更 PlatformTarget 以符合 RID:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
</Project>
或變更 RID 以符合 PlatformTarget:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<PlatformTarget>x86</PlatformTarget>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>
</Project>