MSBuild script for compiling each .cs file into an EXE

I previously wrote about using MSBuild to build all .cs files in a directory into a single exe. Here's a companion script that builds every .cs file into a separate exe.

This might be helpful for directories where you keep sets of small projects, where each source file stands alone, that sort of thing.

(I'm posting these things just as simple illustrations to help people along with their own MSBuild things)

<Project xmlns=""

<!-- This build file compiles each .cs file into its own exe -->

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- Import Project="c:\.net3.5\Microsoft.Csharp.targets" / -->

<PropertyGroup Condition="'$(Configuration)'==''">
<Configuration>Debug</Configuration> <!-- Default -->

<PropertyGroup Condition="'$(Configuration)'=='Debug'">

<!-- Specify the inputs by type and file name -->
<CSFile Include="*.cs" />

<!-- specify reference assemblies for all builds in this project -->
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System.Printing" />
<Reference Include="ReachFramework" />

<Target Name="CompileEach"

<!-- ResolveAssemblyReferences resolves the short names of the assemblies -->
<!-- named in the @(Reference) vector, into fully-qualified DLL names. -->
<!-- The task is defined in the Microsoft.Csharp.targets file. -->
<!-- The output of it is the @(ReferencePath) vector. -->

<Message Text="Reference = @(Reference)" />
<Message Text="ReferencePath = @(ReferencePath)" />

<!-- Message Text="MS Build Tools path: $(MSBuildToolsPath)" / -->

<!-- Run the Visual C# compilation on EACH .cs file. -->
<!-- see for more info -->
<!-- By using the %(CSFile.identity) scalar, we run this task once for each -->
<!-- file. The converse would be @(CSFile.identity). That would run the compile -->
<!-- once, for all files, compiling them all together into a single assembly. -->
<!-- Not what we want here. -->



To use it, run this:
    c:\windows\Microsoft.NET\Framework\v3.5\msbuild.exe build.xml

Skip to main content