Embedding DLLs in a Compiled Executable

The Problem

For fun I am building a building a multi-platform screen saver in C# that I want to execute as a UWP (Universal Windows Platform) app and as classic screen saver using WPF (Windows Presentation Foundation).

This requires the logic to be left in PCLs (Portable Class Libraries), which results in a bunch of DLLs in the output directory. To build a classic screensaver I need a single EXE. So I went looking for a way to embed all resources in a single EXE.

Stack Overflow to the Rescue


Ok, the fact that this exists and is so easy to use is simply blowing my mind.

  1. Install-Package Costura.Fody
  2. Install-CleanReferencesTarget

Build your project and check the app.publish folder in your output directory (\bin\Debug\app.publish)

For my screen saver project I simply need to rename the extension from exe to scr and I am done. Now to figure out the installer part. 🙂

Screens Saver Gallery

The UWP is already in the Windows App Store. I must warn you, its not like a classic screen saver that opens after inactivity, that’s not available for UWP (Universal Windows Platform) apps. Its basically a full screen app that shows pretty pictures.

Its free, try it out. 🙂