You need to use Visual Studio (VS) command prompt and mention the C# code file names (*.cs) of all the Windows forms in your project. You must include each form's code-behind file as well as designer code-behind file. Otherise, the compilation will not succeed.
A sample project structure is as below:
WindowsFormsApplication1.csproj
--Program.cs
--Form1.cs
----Form1.Designer.cs
--Form2.cs
----Form2.Designer.cs
The compilation command for above project will look like:
csc /target:winexe Program.cs Form1.cs Form1.Designer.cs Form2.cs Form2.Designer.cs
Note: It is compulsory to include Program.cs
file during compilation, else the compiler fails to obtain the project's entry point(the Main
method). The /target
switch helps you to launch the output EXE file as a GUI based Windows Forms application.
There is a shorter version of the above command which uses wildcard to include all the files names in one go:
csc /target:winexe *.cs
The easiest alternative is to use the msbuild
command in place of csc
on Visual Studio command prompt. msbuild
command can be used to build the project file which contains the reference of all the *.cs
files. Here is how the command looks like:
msbuild WindowsFormsApplication1.csproj
This relieves us from mentioning all the C# code file names individually (whether in project root directory or nested sub-direcotries). Build the project file and you are done.