Building an ASP.Net Web Application with Hudson

Building a .Net application with Hudson is easy: simply invoke MSBuild as you would do from the command line to compile the application. 

  • C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe /target:Rebuild /p:Configuration=Release /p:Architecture=x86 ConsoleApplication1.csproj

Some best practices:

  • prefer a full build (/target:Rebuild) to an incremental one (/target:Compile)
  • compile in release mode (/p:Configuration=Release), not in debug
  • specify the target architecture (/p:Architecture=x86) to avoid machine-dependent builds.

However, for ASP.Net Web Applications, things are a little trickier. Visual Studio has a "Publish" action to publish only the required files, but this action is not standard to MSBuild.

First, notice that the Web Application project file (WebApplication1.csproj in my test case) holds an almost hard-coded reference:

  • <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />

Unfortunately, the MSBuild Extension Pack does not contain this file. Instead, this file comes from Visual Studio itself. On your build machine, you have to copy
this file to C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets(you will have to create some of the folders).

Then, you have to add two targets to your build: ResolveReferences and _CopyWebApplications. The first one copies files from dependent projects, whereas the second one copies required files from the web project.

Finally, you need to specify both the OutDir and WebProjectOutputDir variables. Here is the command line:

  • C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe /target:Rebuild,ResolveReferences,_CopyWebApplication /p:Configuration=Release;Architecture=x86;WebProjectOutputDir=build\Release\Web\;OutDir=build\Release\Web\bin\ WebApplication1\WebApplication1.csproj

Make sure the OutDir and WebProjectOutputDir have a trailing "\". Otherwise, you will get an error.

For some unknown reason, Hudson removes the trailing backslash from the options so I suggest doubling it.

In the end, you should have something looking like:

BuildAspNetWebApplication-5.pngThe build\Release\Web\ directory should only contain necessary files:

BuildAspNetWebApplication-3.pngAnd the build\Release\Web\bin\ directory should contain all of the required DLLs:

BuildAspNetWebApplication-4.pngReferences:

posted @ 2013-09-13 13:10  邹邹  Views(134)  Comments(0Edit  收藏  举报