ASP.NET MVC and MSBuild via Command-Line

I struggled with this one for a couple hours & wanted to post some help. I'm trying to move towards better deployment processes. I'd like to use TeamCity but until then, command-line will do. It's how I roll anyways.

When I first ran MSBuild on my ASP.NET MVC CSPROJ file I got the following error:

C:\Projects\MvcApplication.WebUI>msbuild /p:Configuration=Debug MvcApplication.csproj
Microsoft (R) Build Engine Version 2.0.50727.3053
[Microsoft .NET Framework, Version 2.0.50727.3603]
Copyright (C) Microsoft Corporation 2005. All rights reserved.

Build started 5/18/2010 9:27:29 PM.
__________________________________________________
Project "C:\Projects\MvcApplication.WebUI\MvcApplication.csproj" (default targets):

Target ResolveProjectReferences:
C:\Projects\Assembly.csproj(200,11): error MSB4019: The imported project "C:\Microsoft
.CSharp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
Done building target "ResolveProjectReferences" in project "Spinsix.Lincs.WebUI.csproj" -- FAILED.

Done building project "MvcApplication.WebUI.csproj" -- FAILED.

Build FAILED.
C:\Projects\Assembly.csproj(200,11): error MSB4019: The imported project "C:\Microsoft.CSh
arp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
0 Warning(s)
1 Error(s)

Time Elapsed 00:00:00.12


The trick here is the Environment Variables that Visual Studio sets up for you. So you need to run the following in order to get them setup:


C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat
or
C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat


Or if you are writing a Build Script / Batch file, simply do:

cd C:\Program Files\Microsoft Visual Studio 9.0\VC\
call vcvarsall.bat >NUL
cd C:\Projects\MyProject\
msbuild /p:Configuration=Debug MvcApplication.csproj
xcopy /a /e (whatever other options) *.* x:\SomeDestination


Hope that helps someone!

Comments

Popular posts from this blog

Require comment / message on all SVN commits for Visual SVN Server

Fluent NHibernate - Incorrect syntax near the keyword 'Group'

Deleting Cookies (or Managing Cookie Domains) in ASP.NET