• Home
  • Tutorials
  • Development Tools
  • Contact Us

Developing Software

Mastering Software Craftsmanship

How to make a .NET application portable

22nd November 2015 by @developingsoft

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:

Install-Package Costura.Fody

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.

Merged Assemblies

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 .csproj file:

<Target AfterTargets="AfterBuild;NonWinFodyTarget" Name="CleanReferenceCopyLocalPaths">
    <Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
</Target>

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.

Share this on:

Filed Under: Tutorials Tagged With: C#, Windows

Search

Advertisement

Newsletter

Subscribe now to receive practical tips on how to become a better software developer.

Free - No Spam - 100% Email Privacy

Featured Posts

Abstract Factory Pattern: C# Example Using the Unity Game Engine

23 Software Design Patterns That Will Make You a More Effective Programmer

How to Deploy an ASP.NET Core Website to Ubuntu with Git

How to Run an ASP.NET Core Website in Production on Ubuntu Linux

How to Install the Edimax Wireless nano USB Adapter on Windows IoT Core for Raspberry Pi

How to Convert a Post Title into a Friendly URL (Slug) in C#

How to Convert Markdown to HTML in ASP.NET Core

How to Send an E-Mail with ASP.NET Core and Mailgun

How to Generate a Sitemap in ASP.NET MVC and ASP.NET Core

How to Create an MD5 Hash of a String in C# and Displaying a Gravatar Image

© 2014–2023 Developing SoftwareTerms • Privacy