NET Core Single Executable Console Application
I have a simple .NET Core Console Application
We can now make a single .EXE runnable Console Application file in .NET Core 3
Whooooo!!!
Here is my Open Source project which looks in your current directory and opens up the .sln file in Visual Studio. It is a tool I use every day for the last few years
Lets bring it up to the latest version of .NET Core 3.1 and just have a single .exe file to distribute. (handy check to see what version of .NET Core you’ve got installed dotnet --version
)
Single File Executable
From MS Docs if you run the following command you’ll get a single exe.
dotnet publish -c Release -r win10-x64 -p:PublishSingleFile=true
Wow this is a large exe for essentially a very simple app, lets make it smaller:
Assembly Linking to make smaller
Assembly linking docs - add in PublishedTrimmed
<PropertyGroup>
<OutputType>Exe</OutputType>
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>d</AssemblyName>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
Lets run publish again and see if the trimmed exe is smaller:
dotnet publish -c Release -r win10-x64 -p:PublishSingleFile=true
Better!
Scott Hanselman has a good post on this but I couldn’t get it working as he did with all config in the .csproj file.
4th July 2020 Update
After a strange error that I’m not sure why happened:
“An assembly specified in the application dependencies manifest (d.deps.json) was not found: package: ‘runtimepack.Microsoft.NETCore.App.Runtime.win-x64’, version: ‘3.1.3’ path: ‘Microsoft.Win32.Registry.dll’”
I recompiled the solution again using VS tooling which is nice:
Conclusion
It makes me very happy to be able to distribute a single .exe again for my console apps.