Invoke a publish from msbuild for visual studio 2012

John Livermore picture John Livermore · Aug 31, 2012 · Viewed 13k times · Source

For VS2010 and before I was utilizing Web Deployment Projects (WDP) to help package my website for production deployment. I had a MSBuild script that compiled the solution in release mode. An output of that was production ready website files compiled and cleaned by the WDP.

I see for 2012 WDP have been removed, and a new tab has been created in the properties for the web application. The options are the same, but now the invocation of this is done via the Publish option (before you just compiled in release mode).

So the question is this. From an MSBuild script, how do I invoke a Publish operation? I found some old posts that...

msbuild /target:publish

would do the trick. But that doesn't seem to work in 2012.

Also, I tried in my msbuild task...

<MSBuild Properties="Configuration=Publish;" 
         StopOnFirstFailure="true" 
         Projects="$(BuildDirectory)\MySolution.sln"></MSBuild>

...but msbuild just reported "unknown configuration".

How can I have msbuild run the publish option from the command line?

Answer

Norman H picture Norman H · Feb 27, 2013

It appears that there are now some other options for publishing from the command-line. Specifically something along the lines of the following seems possible now with some RC updates to Visual Studio 2012.

msbuild mywap.csproj /p:DeployOnBuild=true;PublishProfile=MyProfileName

For more details check out this post by Scott Hanselman and check out the section on Publishing.