Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error NETSDK1031: It is not supported to build or publish a self-contained application without specifying a RuntimeIdentifier

I am running following command to publish .NET CORE 5.0 web api project using command line on windows 10 box.

c:\test\Service>dotnet publish -c release Emp.sln --framework net5.0 /p:DebugType=None /p:DebugSymbols=false --nologo --self-contained --runtime linux-x64 -v m

But I am getting following error:

C:\ProgramFiles\dotnet\sdk\5.0.403\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(126,5): error NETSDK1031: It is not supported to build or publish a self-contained application without specifying a RuntimeIdentifier. You must either specify a RuntimeIdentifier or set SelfContained to false. [c:\test\Service\emp.csproj]

Why I am getting this error when I am specifying --runtime flag? I am able to publish using Visual Studio without any issues.

like image 968
OpenStack Avatar asked Nov 28 '25 05:11

OpenStack


1 Answers

I am able to resolve the issue by adding <RuntimeIdentifier>linux-x64</RuntimeIdentifier> line in .csproj file:

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

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <RuntimeIdentifier>linux-x64</RuntimeIdentifier>

With this I am able to build solution using command line but when running the app through Visual Studio on Windows machine, I am getting error:

The debug executable ''c:\user\testuser\emp\bin\debug\net5.0\linux-x64\textdb.exe' specified in the 'emp' debug profile does not exists

I am able to solve the second issue (being able to build on Windows using Visual studio & being able to publish targeting Linux using command line) by add this to csproj file. Specifying multiple values in RuntimeIdentifiers

 <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <RuntimeIdentifiers>win10-x64;linux-x64</RuntimeIdentifiers>
  </PropertyGroup>
like image 198
OpenStack Avatar answered Nov 30 '25 19:11

OpenStack