MSBuild can be a bit of a bear, and having a build procedure around .Net web apps has never been neat or easy. Apparently hotmail and bing are deployed by some guy at Microsoft clicking on the ‘publish’ button in Visual Studio. But for those of us creating mission critical web apps, this is not the thing to do (to quote Green Velvet).
We use a set of centralized imports in all our projects to standardize the behaviour of all builds with a minimum of fuss. These excerpts are the hacks you can use to get your build server churning out your web apps. You may need to work with the order in your
*proj file since some of the default msbuild targets will override some properties (
WebProjectOutputDir for instance.)
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <!-- ... --> <PropertyGroup> <!-- path where you want your builds --> <BuildRoot>c:\build\foo\bar</BuildRoot> <!-- Can be a handy property, here we use it to name our output path --> <ProjectFolderName>$( [System.Text.RegularExpressions.Regex]::Match( $(MSBuildProjectDirectory), "[^\\]+$").Value )</ProjectFolderName> <!-- Makes our scripts a little neater, you will find this GUID in your web app csproj --> <WebProjectGuid>349c5851-65df-11da-9384-00065b846f21</WebProjectGuid> </PropertyGroup> <!-- Properties we set/override if it's a web project. Notice the condition? --> <PropertyGroup Condition="$(ProjectTypeGuids.Contains($(WebProjectGuid)))"> <!-- Just for our use, not used by any standard msbuild targets --> <WebBuildRoot>$(BuildRoot)\web</WebBuildRoot> <!-- Content gets copied here by _WPPCopyWebApplication with transforms, etc --> <WebProjectOutputDir>$(WebBuildRoot)\$(ProjectFolderName)</WebProjectOutputDir> <!-- This is where assemblies end up for a csproj --> <OutputPath>$(WebProjectOutputDir)\bin\</OutputPath> </PropertyGroup> <!-- ... --> <!-- This target does nothing, but causes the '_WPPCopyWebApplication' to get invoked after the build target, neatly putting our web project in our build folder, yay! --> <Target Name="PostWebBuildContentCopy" AfterTargets="Build" Condition="$(ProjectTypeGuids.Contains($(WebProjectGuid)))" DependsOnTargets="_WPPCopyWebApplication"> </Target> <!-- ... --> </Project>
msbuild /t:build if ‘build’ is not your default) will cause your assemblies to get built to
c:\build\foo\bar\web\WcfAppName\bin and then appropriate web files placed in
- INFO: List of known project type Guids @ mztools