I have a .Net Core 3 console application that i'm trying to publish as a self contained single executable. I've been able to do this in the past but to my suprise it no longer works. The project structure is a console application with two assemblies, all in Core 3.
If i use dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true
i expect the output to be a single executable of several mb's in size. However the publish folder contains the executable (few hundred kb) and a .dll file together with .cache files and the pdb.
The config for my console app is as follows:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
If i publish the app directly from Visual Studio i get the same results as above.
So my question boils down to: Why doesnt this configuration or publish statement result in a self contained single executable?
The referenced project is a non self-contained executable. A non self-contained executable cannot be referenced by a self-contained executable.
A self-contained application consists of a single, installable bundle that contains your application and a copy of the JRE needed to run the application. When the application is installed, it behaves the in the same way as any native application.
I can get my 3.1 console app to publish with the following:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>..\..\Binaries\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<DebugType>None</DebugType>
</PropertyGroup>
</Project>
If I set PublishReadyToRun to True (or add PublishTrimmed as True) it fails. Adding DebugType None prevents it publishing the pdb file for the exe.
UPDATE: removing the SelfContained tag stops it creating the 'dotnetcoreapp3.1' folder.
According to the command line release, I tested successfully. A single executable file was generated. If you have always failed to publish, I suggest you use VS to publish.The publishing process is as follows:
1.Right click on the project->publish
2.Change configuration
3.Save the configuration and click Publish
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With