In my last post, I announced a free application called Hosts Editor, a tool that I created for editing the Windows hosts file. At first, the application required installation. And then a user on GitHub suggested It would be better to make the application portable. It turns out, this is pretty easy when using a tool called Costura. In this post, I will show you how to make a .NET application portable by merging the DLL files into the programs .EXE file.
Making a .NET application portable
Making a .NET application portable is straight forward if you use a tool called Costura. All you need to do, is add the package to your project using NuGet with the following command:
Now when you build your project you will notice that the .EXE file is bigger than what it was before you added the NuGet package. The image below shows the difference in sizes for the Hosts Editor project.
How to remove the DLL files from the output folder
As you can see in the image above, the DLL files are still in the output folder even though they have been merged into the .EXE. To remove the files on build, you can add the following line to your
<Target AfterTargets="AfterBuild;NonWinFodyTarget" Name="CleanReferenceCopyLocalPaths">
<Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
Note: You may have to change the way you store/retrieve settings as putting them in the
app.config file means you will have two files to deploy. For the Hosts Editor application I used a
config.json file and Json.NET to store settings in the Program Data folder.