17

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.

SharpCoder
  • 18,279
  • 43
  • 153
  • 249
OpenStack
  • 5,048
  • 9
  • 34
  • 69
  • 2
    You can check issues on github, maybe you will find good solution for your case: https://github.com/dotnet/sdk/issues/10902 and https://github.com/dotnet/sdk/issues/10566 – Lukasz Szczygielek Dec 07 '21 at 00:55

1 Answers1

24

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>
SharpCoder
  • 18,279
  • 43
  • 153
  • 249
OpenStack
  • 5,048
  • 9
  • 34
  • 69