I really like the fact that MSBuild is installed with the .Net Framework so you do not have to install a separate build tool. Unfortunately, if you are developing Web Application projects (WAP), you may discover something is missing.

In my case, I am building a VS2008 project and the build server does not have Visual Studio installed. No problem, right? Wrong.

It turns out that when you install VS, it deploys some additional targets to the MSBuildExtensionsPath. Without these targets, when you run the build, you will see:
error MSB4019: The imported project "C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.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.

This is in direct reference to your WAP *.csproj file.
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />

If you search for MSB4019, you will find a few different resolutions. Here are a couple.
  1. Add a condition to the <Import> element that basically verifies the target file exists. Because you are modifying your csproj file directly, VS may warn you about it. I am not a great fan of this approach, but it appears to work. I think perhaps the reason is because the import is only necessary when building the project from within VS.
  2. Deploy the target files to your build server. I copied the entire contents of <MSBuildExtensionsPath>/Microsoft/Visual Studio from my development box (which has VS2008 installed) to the build server.

The same issue arises with VS2005.

Anyway, I hope this clarifies the issue and helps someone.

Tags: ,
posted on Tuesday, February 26, 2008 8:10 AM
Filed Under [ Builds & CI .Net MSBuild Tools ]

Comments

Gravatar
# re: MSBuild Server Gotcha
posted by Jeff Hunsaker
on 2/26/2008 12:13 PM
The WebApplicationSetup.msi includes and installs the .targets file as well. Instructions.

Also, I *believe* the .Net SDK installs this file now too.
Gravatar
# re: MSBuild Server Gotcha
posted by Will Smith
on 2/26/2008 2:34 PM
Hmm... I see that this is in reference to 2005 WAPs. Does the same setup apply for 2008 projects? A friend of mine suggested that I could install a VS Express Edition on my build server to ensure all the necessary components are available.

Thanks for your feedback.
Gravatar
# re: MSBuild Server Gotcha
posted by Jeff Hunsaker
on 2/28/2008 8:18 AM
Dang, I can't get the v9.0 microsoft.webapplication.targets to install off anything: .Net 3.5 Framework, ASP.Net 3.5 Extensions CTP, ... For now, I think it necessitates a manual copy from a VS.Net 2008-installed machine onto a VS.Net-less build server. ;-( This would be a good one to pose to the ASP.NET Forums.
Gravatar
# re: MSBuild Server Gotcha
posted by Derek Morrison
on 1/30/2009 9:17 AM
I even get this on Vista 64, where the the .targets file is installed in "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications" (note the x86 part of the path). When MSBuild runs locally (outside of Visual Studio), it still looks in this directory: "C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications" (without the x86 part).

I was just testing locally until I moved to a build server, but I could have fixed it two ways: by adding the /p:MSBuildExtensionsPath="C:\Program Files (x86)\MSBuild" switch to the msbuild command, or by copying files under "C:\Program Files (x86)\MSBuild" to "C:\Program Files\MSBuild".

Post A Comment
Title:
Name:
Email:
Comment:
Verification: