SumOne
SumOne

Reputation: 91

error NETSDK1032: The RuntimeIdentifier platform 'win-x86' and the PlatformTarget 'x64' must be compatible

My Solution is:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29613.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core31ConsoleApp", "Core31ConsoleApp\Core31ConsoleApp.csproj", "{06477443-295A-47CA-A36E-A3F6B3AE47AC}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|x64 = Debug|x64
        Debug|x86 = Debug|x86
        Release|x64 = Release|x64
        Release|x86 = Release|x86
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {06477443-295A-47CA-A36E-A3F6B3AE47AC}.Debug|x64.ActiveCfg = Debug|x64
        {06477443-295A-47CA-A36E-A3F6B3AE47AC}.Debug|x64.Build.0 = Debug|x64
        {06477443-295A-47CA-A36E-A3F6B3AE47AC}.Debug|x86.ActiveCfg = Debug|x86
        {06477443-295A-47CA-A36E-A3F6B3AE47AC}.Debug|x86.Build.0 = Debug|x86
        {06477443-295A-47CA-A36E-A3F6B3AE47AC}.Release|x64.ActiveCfg = Release|x64
        {06477443-295A-47CA-A36E-A3F6B3AE47AC}.Release|x64.Build.0 = Release|x64
        {06477443-295A-47CA-A36E-A3F6B3AE47AC}.Release|x86.ActiveCfg = Release|x86
        {06477443-295A-47CA-A36E-A3F6B3AE47AC}.Release|x86.Build.0 = Release|x86
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {17BBBF08-C7F4-4F6A-AD8F-32F2F3F21D27}
    EndGlobalSection
EndGlobal

Console project is:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <Platforms>x86;x64</Platforms>
  </PropertyGroup>

</Project>

This project contains only one C# "Program.cs" file which contains its default content:


using System;

namespace Core31ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

As you see, it's more or less new console app created for .Net Core 3.1. The only modification I did, is "Any CPU" architecture replaced with x86 and x64. It can be successfully built with VS for all combinations of Release/Debug and x86/x64.

When I try any of two following commands from cmd/powershell it also builds successfully.

dotnet build Core31ConsoleApp.sln --configuration Debug --runtime win-x64
dotnet build Core31ConsoleApp.sln --configuration Release --runtime win-x64

The problem starts when I try one of those two:

dotnet build Core31ConsoleApp.sln --configuration Release --runtime win-x86
dotnet build Core31ConsoleApp.sln --configuration Debug --runtime win-x86

They fail and following error message appear:

C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(151,5): error NETSDK1032: The RuntimeIdentifier platform 'win-x86' and the PlatformTarget 'x64' must be compatible.

This is minimal solution which reproduce this issue, but I have a much bigger and identically configured solution which fails a bit different way:

C:\Program Files\dotnet\sdk\3.1.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(151,5): error NETSDK1032: The RuntimeIdentifier platform 'win-x64' and the PlatformTarget 'x86' must be compatible.**

It fails for the first two commands and works for the second pair. It's probably because larger solution have different order in this section:

GlobalSection(SolutionConfigurationPlatforms) = preSolution
    Debug|x64 = Debug|x64
    Debug|x86 = Debug|x86
    Release|x64 = Release|x64
    Release|x86 = Release|x86
EndGlobalSection

I'm working on Win 10 Prof machine (Intel's I7) with VS2019 and .Net Core 3.1 SDK (64-bit) installed during one of the recent VS updates. System and all the software installed is up to date.

I completely don't know what is wrong here or what I'm doing wrong.

I will be grateful for any help.

Upvotes: 9

Views: 14556

Answers (6)

mbielecki1
mbielecki1

Reputation: 104

My case:

  1. Update by myself .net framework from 6 to 7 (because of project migration)
  2. Then update the Visual Studio

then I get this error...

My own installation and .net SDK 7 seem to not work together correctly.

enter image description here

I uninstalled my own installation and left this from Visual Studio. All start working.

Upvotes: 0

James Lawruk
James Lawruk

Reputation: 31383

Similar to pdshuller's answer, I simply removed the <PlatformTarget> node from the project (.csproj) file, which did not match the <RuntimeIdentifier> value in the publish profile (.pubxml) file.

<PropertyGroup>
  <TargetFramework>net6.0</TargetFramework>      
  <SpaRoot>ClientApp\</SpaRoot>
  <Configurations>Local;Development;Test;Production</Configurations>
  <!-- Removed this <PlatformTarget>x86</PlatformTarget> -->
</PropertyGroup>

Upvotes: 0

zhixuan yang
zhixuan yang

Reputation: 1

Project Setting -> Generate -> target platform -> AnyCPU -> Save ! ok!

dotnet publish -r win-x86 -c Release --self-contained

dotnet publish -r win-x64 -c Release --self-contained

Upvotes: 0

pdschuller
pdschuller

Reputation: 584

My error message was different but my fix may be applicable. Error was:

The RuntimeIdentifier platform 'browser-wasm' and the PlatformTarget 'x64' must be compatible.

The project is a Blazor WebAssembly project. The csproj file had this in it:

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>

I replaced the x64 with anycpu which was suggested my another error message I got after I replaced the x64 with browser-wasm. Ha.

Before the fix all my references/Dependencies in Solution Explorer had warning triangles on them. And the markup was saying things like, I have no idea what DxDataGrid is. Do you need an @using statement. That all went away after this fix.

Upvotes: 3

CubeSpark
CubeSpark

Reputation: 23

Adding a value to the node "RuntimeIdentifier" is not useful. Let me ask you, how did you load the COMMAND prompt? Did your taskbar or icon use a BATCH file? Did it use

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat

If so, you may be running "dotnet build" using the C++ command environment that is created by that batch file.

ANSWER: do not use a VC++ Command Environment to run ASP.NET Core CLI. Instead, use a Command Environment that is configured properly for ASP.NET Core CLI commands. How do I know this? If you look at vcvarsall.bat, you will see, on line 71 to 75 of that batch file, the following gotcha:

@REM This temporary environment variable is used to control setting of VC++ 
@REM command prompt-specific environment variables that should not be set
@REM by the VS Developer Command prompt (specifically vsdevcmd\ext\vcvars.bat). 
@REM The known case this effects is the Platform environment variable, which 
@REM will override platform target for .NET builds.

Instead, use the one that came with VS2019, as in your Windows Start Menu. The command window should look similar to this:

Visual Studio "boxed" Command

Shown below, I compiled a WASM, and it works as long as you have the correct MS Build environment, which is set correctly in the VS 2019 Command Environment:

Build Success! Use the Command Environment that comes with VS 2019

Upvotes: 2

Sundeep
Sundeep

Reputation: 2135

Since this is an executable try adding <RuntimeIdentifier>win</RuntimeIdentifier> in the TargetFramework Property Group.

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RuntimeIdentifier>win</RuntimeIdentifier>  // add this
    <Platforms>x86;x64</Platforms>
  </PropertyGroup>

Upvotes: 0

Related Questions