Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MSBuild, how do I build an MVC4 solution from the command line (applying Web.config transformations in the process) and output to a folder?

I think the question title pretty much said it all, but for clarity, I am trying to:

  1. Build a VS2010 ASP.NET MVC4 solution from the command line (MSBuild), specifying a solution configuration (e.g. Release)
  2. Apply any Web.config transformations for that configuration during the process
  3. Output the results into a folder on the local machine (no IIS, agents, zip files, FTP, packages etc, just a folder containing all the files required to run that web site)

I've been trying to figure this out for almost a week now, through the Microsoft docs (which are spectacularly unhelpful), other answers on SO and general Googling. I don't know if I'm just not getting it (which is entirely possible), or if MSBuild/MSDeploy really is the cryptic mess it currently appears to be.

Is there a reasonably simple way to achieve this? Help, please!

like image 355
Mark Bell Avatar asked Mar 07 '13 14:03

Mark Bell


1 Answers

If you are running VS2010: ensure you have the Azure 1.7+ SDK installed (even if you're not publishing to Azure, it adds the VS2012 publishing features to VS2010)

VS2012+ have these featured built in

msbuild ProjectFile.csproj /p:Configuration=Release ^
                           /p:Platform=AnyCPU ^
                           /t:WebPublish ^
                           /p:WebPublishMethod=FileSystem ^
                           /p:DeleteExistingFiles=True ^
                           /p:publishUrl=c:\output

Or if you are building the solution file:

msbuild Solution.sln /p:Configuration=Release ^ 
                     /p:DeployOnBuild=True ^
                     /p:DeployDefaultTarget=WebPublish ^
                     /p:WebPublishMethod=FileSystem ^
                     /p:DeleteExistingFiles=True ^
                     /p:publishUrl=c:\output

Either way, you can also set /p:PrecompileBeforePublish=true and the output will be a precompiled version of the site.

Once you have the Azure SDK installed you would usually create a publish profile and simply use /p:PublishProfile=DeployToFolder but I've given you the manual command line in case you're not interested in going all-in with the new publishing stuff.

like image 132
Richard Szalay Avatar answered Oct 13 '22 20:10

Richard Szalay