Single File Publishing

When you publish your programs probably you see bunch of other files along with your executable. You may want package your published files to single file. Here is how to do it:

Edit your project file. Add these lines to your config file.

<!-- Publish single file settings -->
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishReadyToRun>true</PublishReadyToRun>
<!-- Publish single file settings -->

Your project file will look like this:

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

	<PropertyGroup>
		<OutputType>Exe</OutputType>
		<TargetFramework>net6.0</TargetFramework>
		<ImplicitUsings>enable</ImplicitUsings>
		<Nullable>enable</Nullable>
		<!-- Publish single file settings -->
		<PublishSingleFile>true</PublishSingleFile>
		<SelfContained>true</SelfContained>
		<RuntimeIdentifier>win-x64</RuntimeIdentifier>
		<PublishReadyToRun>true</PublishReadyToRun>
		<!-- Publish single file settings -->
	</PropertyGroup>

	<ItemGroup>
		<Using Include="System.Text.RegularExpressions" />
	</ItemGroup>

</Project>

For more information you might want to take a look at this link:
https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?tabs=cli

Happy coding…

Posts created 141

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top