It’s been a while since my last blog post, but as promised here is an example of a MSBuild script. I have made a simple .NET 2.0 web application utilizing the MSBuild script. The web application source code can be downloaded here.
Web Application Folders and Files

- Config – contains the environment (dev, test, prod), user, and machine configurations
- Core – contains the application’s source code
- Library – contains the third party libraries and tools used by the application
- PrecompiledWeb – generated folder containing binaries for the web application
- Publish – generated folder containing NCover and NUnit results
- Web – contains the web application files
- build.bat – batch file used to execute MSBuild script
- main.build - MSBuild script
Executing MSBuild Script
To simplify running the MSbuild script, a batch file has been created to allow the user to specify the MSBuild target to execute and which configurations to use.

Usage
build [target] [environment]
[target] – Specifies the MSBuild target to execute
[environment] – Specifies the environment (dev, test, prod)
Notes
- If the environment is not specified, the build will attempt to use the configurations from <user>.config
- if <user>.config does not exist, it will attempt to use the configurations from <machine>.config
- if <machine>.config does not exist, it will use dev.config
- If the target is not specified, the build will use the build target
MSBuild Targets
These are the available targets for the MSBuild file:
- Config – generates the Web.config and App.config based off the specified environment
- Clean - performs a Clean on the solution and deletes the generated folders
- Prepare – generates the folders for NUnit and NCover results
- Compile - performs a Build on the solution
- Test - runs NUnit for the Unit Tests
- Coverage – runs NCover for the code coverage
- Build - default target
- Cruise - Cruise Control target
- CleanDeploy – removes the folders and files from the deployment folder
- PrepareDeploy – performs a Build on the solution
- Deploy - deploys the application’s binaries to the deployment folder
Please take a look over the MSBuild file and feel free to contact me with any feedback. In my next post, I will walkthrough the elements in the MSBuild file.
<!– Application Configurations –>
<PropertyGroup>
<SolutionFileName>MSBuildExample.sln</SolutionFileName>
<WebDir>Web</WebDir>
</PropertyGroup>
<!– Test Assemblies –>
<ItemGroup>
<TestAssemblies Include=“UnitTests\bin\Debug\MSBuildExample.UnitTests.dll“ />
</ItemGroup>
<!– Build Configurations –>
<PropertyGroup>
<Default>default</Default>
<Dev>dev</Dev>
<Test>test</Test>
<Prod>prod</Prod>
<ConfigDir>Config</ConfigDir>
<DevConfig>$(ConfigDir)\$(Dev).build</DevConfig>
<TestConfig>$(ConfigDir)\$(Test).build</TestConfig>
<ProdConfig>$(ConfigDir)\$(Prod).build</ProdConfig>
<UserConfig>$(ConfigDir)\$(USERNAME).build</UserConfig>
<MachineConfig>$(ConfigDir)\$(COMPUTERNAME).build</MachineConfig>
<PrecompiledWebDir>PrecompiledWeb</PrecompiledWebDir>
<WebOutputDir>$(PrecompiledWebDir)\$(WebDir)</WebOutputDir>
<PublishDir>Publish</PublishDir>
<NUnitPublishDir>$(PublishDir)\NUnit</NUnitPublishDir>
<NCoverPublishDir>$(PublishDir)\NCover</NCoverPublishDir>
</PropertyGroup>
<!– Tool Configurations –>
<PropertyGroup>
<NCoverExplorerToolPath>Library\NCoverExplorer</NCoverExplorerToolPath>
<NCoverToolPath>Library\NCover</NCoverToolPath>
<NUnitToolPath>Library\NUnit</NUnitToolPath>
</PropertyGroup>



0 Responses to “MSBuild Example”