It is not supported to publish an app to a single file without RuntimeIdentifier

Issue Description:

.NET Core build gives below error,

It is not supported to publish an application to a single-file without specifying a RuntimeIdentifier. Please either specify a RuntimeIdentifier or set PublishSingleFile to false.

You might get this error on CLI or using Visual Studio IDE.

Resolution:

The issue I found to be not specifying the runtime identifier in the project file or through the publish command.

When choosing an option to create a single exe file for multiple dll or apps

Runtime identifier using CLI

Please specify the runtime identifier as below,

dotnet publish -r linux-x64 -p:PublishSingleFile=true 

OR 

dotnet publish -r win10-x64 -p:PublishSingleFile=true

Runtime identifier using Project File

Here below is sample project file,

For Linux

<Project Sdk="Microsoft.NET.Sdk">
 
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
    <PublishSingleFile>true</PublishSingleFile>
  </PropertyGroup>
 
  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\ExternalApp1\ExternalApp1.csproj" />
    <ProjectReference Include="..\ExternalApp2\ExternalApp2.csproj" />
  </ItemGroup>

 
</Project>

For Windows

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
    <PublishSingleFile>true</PublishSingleFile>
  </PropertyGroup>

Specify multiple Runtime

You will not be able to specify multiple runtimes while using CLI, However, you can specify commands multiple times for the supported target version.

dotnet publish -r linux-x64 -p:PublishSingleFile=true

Other references:

Did the above steps resolve your issue? Please sound off in the comments below!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



Leave a Reply

Your email address will not be published. Required fields are marked *