How to build/link multiple DLLs and an EXE C# projects into one EXE assembly

This is just a quick reference. A couple of blogs mentioning how to do that, but they forget to mention what to do if you have a Windows application (all examples are done with Console apps). So, here it is, briefly:

Let's say, I have 2 projects, one DLL and another one is an EXE Windows application project. I'm referencing the DLL project from the EXE project. Here's how to build and link them together:

1. Build all of you projects (including the EXE project) into netmodules:

cd DllProject

csc.exe /target:module *.cs

cd ../ExeProject

csc.exe /target:module *.cs /addmodule:../DllProject/Class1.netmodule

2. Link them together (and here's the trick that the Windows EXE project also has a Program.Main entry point but you don't see this one):

link /LTCG /verbose /entry:ExeProject.Program.Main /out:SingleFile.exe Form1.netmodule Class1.netmodule /subsystem:windows