How to deploy a web site project using msbuild

How to deploy a web site project using msbuild

A website project differs a bit from a normal web application. The main thing is that it doesn’t require compilation, so how do I deploy this then?

A “normal” msbuild deploy will look like this:

cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

MSBuild "C:\STAGING\website\\.sln" /p:DeployOnBuild=true /p:PublishProfile=ToProduction /p:WebPublishTargetsVersion=11.0 /p:username= /p:password=

If you try to use this on a web site project (provided you created a solution file for it), you will get following error:

The precompilation target directory cannot be in the same tree as the source application directory

“The precompilation target directory () cannot be in the same tree as the source application directory ().”

The solution to this was pretty simple, when you create a publish profile for a web site in Visual Studio it will generate a “website.publishproj” file. It is this file you use to build and deploy, not your solution file.

So the build command will be:

cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

MSBuild "C:\STAGING\website\\website.publishproj" /p:DeployOnBuild=true /p:PublishProfile=ToProduction /p:WebPublishTargetsVersion=11.0 /p:username= /p:password=

4 thoughts on “How to deploy a web site project using msbuild

  1. Thank you so much. It seems that most examples forget to show that you use the publish project, not the solution file. Once I changed to the publish project, the project built and deployed successfully.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.