How to customize your MSBuild project file manually

To hand-modify your managed project file, right click on the project, choose Unload, right click again, choose Edit. After editing (with intellisense!) save and close. Right click on the project, choose Reload. (If you are using Beta 2, after unloading the project, do File>Open>File and choose the project file manually.)

As well as modifying properties and items in this editor, you can even add steps to the build. For example, to generate a new file during the build and get it compiled into the assembly, you could add this just before the closing </Project>

<!– Overriding the BeforeCompile target to insert this step just before the compilation step –>
<Target Name="BeforeCompile">
<!– Use Exec task to create a code file; this could be done more elegantly with a custom task–>
<Exec Command="echo static class BuildMachine { public static string Name { get { return &quot;%COMPUTERNAME%&quot;; }}} &gt; buildMachine.cs" Outputs="buildMachine.cs">
<!– Add this file to the list to compile –>
<Output ItemName="Compile" TaskParameter="Outputs" />
</Exec>
</Target>

Now you can use BuildMachine.Name in your project to programmatically get the name of the machine that built the assembly. You could have achieved this specific example in VS 2003 by creating the file in a pre-build event, or using a compiler define, but there is no way in VS 2003 you could have hooked into the middle of the build process as described above. A more elegant use would be to use a custom task to modify your AssemblyInfo.cs file during the build, to increment the AssemblyVersion attribute.

More info on MSBuild is here https://channel9.msdn.com/wiki/default.aspx/MSBuild.HomePage

Happy Visual Studio’ing!