37

I am using VS 2019 and .Net 5 to build a simple console application. I wanted to share this app with a friend so I tried to publish it as a single file but I keep getting some extra DLLs that the executable needs to run correctly.

Edit: Switching this project to .net core 3.1 works as expected I am able to export a single Exe file without any required DLLs.

Dotnet Cli: dotnet publish -c Release -o publish -p:PublishReadyToRun=true -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true

Csproj:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <PublishSingleFile>true</PublishSingleFile>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="HtmlAgilityPack" Version="1.11.28" />
  </ItemGroup>
</Project>

Output

Bailey Miller
  • 1,376
  • 2
  • 20
  • 36
  • 1
    Does this answer your question? [.NET 5 excludes some libraries from single file publication](https://stackoverflow.com/questions/64778283/net-5-excludes-some-libraries-from-single-file-publication) – magicandre1981 Dec 06 '20 at 17:05

1 Answers1

55

Its known issue that described here: https://github.com/dotnet/runtime/issues/36590

And new dev experience provided here: https://github.com/dotnet/designs/blob/main/accepted/2020/single-file/design.md#user-experience

So in your case you need use p:IncludeNativeLibrariesForSelfExtract=true additionaly.

Full command:

dotnet publish -c Release -o publish -p:PublishReadyToRun=true -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true -p:IncludeNativeLibrariesForSelfExtract=true

or include this flag in .csproj file

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <PublishSingleFile>true</PublishSingleFile>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PlatformTarget>x64</PlatformTarget>
    
   <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>

</PropertyGroup>
Anton Komyshan
  • 1,377
  • 10
  • 21
  • 1
    Link to the article: https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file#other-considerations – Alternatex Jan 30 '21 at 13:45
  • 1
    I publish usually using the *Publish...* UI in Visual Studio. Is there any way to change this property through the UI or do I have to edit the `.csproj` manually? – IneffaWolf Aug 31 '21 at 14:35