Fixing Packaging Of Web Projects On Your .NET Build Server
- Published on
- Reading time
- Authors
- Name
- Simon Waight
- Mastodon
- @simonwaight
On my current project I'm running up the build and deployment environment and hit a roadblock that took me a little while to fathom. Hopefully reading this might save you some time if you're having this issue.
The Scenario
A build server that does not have Visual Studio installed but has an appropriate .Net SDK that allows you to compile projects successfully.
The MSDeploy package on the server - I get mine via the Web Platform Installer (or Web PI for short).
A project that you know has valid deployment settings - typically one you can build and package using Visual Studio locally.
When building on the server you compile (build) everything OK but the packaging fails silently.
If this sounds like your situation (or similar to it) read on to find a solution.
The Clue
It took me a while to work this out and to be honest the Google Gods were not much use to me (including Scott Guthrie's blog on all this - see if you can find the follow on blog on automating packaging he hints at).
I tried a range of things before I came across a post on Stack Overflow that pointed me in the right direction. It refers to the much maligned Microsoft.WebApplication.targets that is installed along with Visual Studio but which is gloriously missing when you build a clean server without Visual Studio. You've probably come across that file before because trying to build without it with Web Application projects ends up with nasty errors being emitted from MSBuild:
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the `<Import>` declaration is correct, and that the file exists on disk.
So you know how to fix that - you copy across the necessary files from a machine with Visual Studio and recreate that folder structure on your build server. Done.
The Fix
The Stack Overflow post specifically mentions that understanding how the MSDeploy stuff works basically boils down to reading the contents of the Microsoft.WebApplication.targets file.
Hang on, what's that got to do with packaging?
So I cracked open the targets file and sure enough at one point in it it reads clearly (including good grammar):
<!--This will be overwrite by ..\web\Microsoft.Web.Publishing.targets when $(UseWPP_CopyWebApplication) set to true-->
OK, so now I'm a bit surprised... didn't MSDeploy lay down some MSBuild support for me? Nope.
At this stage I switched to my working development box and sure enough found a 'Web' folder sitting at the same level as the 'WebApplications' one.
I zipped up the contents of this folder and copied to my build server and placed them in the right location (C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Web).
After this change I re-ran my packaged build and found that the expected build steps and output (a zip and some manifest files) were produced.
So, Hollywood ending to this story then!
Hope it saves you some time.