How to use command line msbuild to deploy VS2012 Web Site project without precompiling it?
Asked Answered
F

2

39

I've inherited a very large VS2012 web site project (not web application) and am trying to automate it's deployment. There are tons of circular references in the project so to get it to precompile using aspnet_compiler.exe I have to turn on fixednames. The problem with that is it causes the build to take about 20 minutes on my quad core, 16gb ram, ssd developer machine. The previous developer didn't have to deal with this as he would just copy the whole source to the production web server.

So before I tackle the circular references issue I want to at least automatically deploy the project using msdeploy. I can use the publish profiles within visual studio and it does exactly what I want:

  1. Builds the referenced DLL's and adds them to the project.
  2. Does the web.config transforms.
  3. Does not even attempt to build the website but just packages into a zip file for me.

What I can't figure out for the life of me is how to get MSBuild.exe to do that exact same thing!

MSBuild.exe WebProject.vs2012.sln /m /T:Build 
    /p:Configuration=Release`;DeployOnBuild=true`;PublishProfile=TestDeploy

The command above still tries to execute aspnet_compiler which is not what I want. The publish profile says that it shouldn't be precompiled... but in the logs I see it executing it.

So: How can I use msbuild to deploy a Web Site Project without precompiling it?

Feverfew answered 11/2, 2013 at 19:27 Comment(0)
R
59

For website project the publish process is not plumbed into the build process. For website project since there is no formal build process there was nothing for us to really extend.

Note: the below contents requires to have VS 2012 (or VS2010 for that matter) and the Azure SDK on top of that. The features were not included in the RTM drop of VS2012.

After creating a publish profile in VS the following are created:

  1. A publish profile (.pubxml file) under App_Data/PublishProfiles
  2. A website.publishproj in the root of the website

The purpose of the website.publishproj is to facilitate command line publishing. It is a fill in for the .csproj/.vbproj which you would normally get when using a Web App Project.

If you would like to automate publishing you can use a command like the following.

msbuild.exe website.publishproj /p:DeployOnBuild=true 
   /p:PublishProfile=<profile-name-no-extension> /p:VisualStudioVersion=11.0

You should not have to specify which targets invoked.

Regarding the message in VS that the site is being pre-compiled, that is a bug. It runs through a pre-compile but the publish uses the setting in the profile. That bug should have been fixed in Visual Studio Update 1. After installing that you should not see the un-necessary pre-compile step. Please let me know if you still do see that.

Rightminded answered 11/2, 2013 at 21:12 Comment(6)
Awesome! I've been looking for a way to do this for days! Thanks!Feverfew
I have looked all over. No website.publishproj is created for my project. I have the Update2 for VS2012 which includes Azure SDK. I have the same command line problems to publish my project from a TeamCity build server.Buckskin
I know this is old but what if you have a website project and you just want to deploy the file that has just been checked-in and not the whole site.Dendroid
This will only work if visual studio is installed on the machineEuchromosome
I guess that means you have to install visual studio on the build server then eh?Subrogate
@Subrogate you shoudn't need to install any additional dependencies on your build server. Assuming that you can build an asp.net project on your build server this would work as well.Rightminded
S
1

While Sayed Ibrahim Hashimi's answer did help me somewhat, here is what I found to be neccessary for VS2012:

After installing the Azure SDK, I created a file publish profile, which created a PublishProfiles folder in the Properties folder of my project. Inside this new folder, two xml files named my_sample_PublishProfile_Foo.pubxml and my_sample_PublishProfile_Foo.pubxml.user where created.

Using the .pubxml, I am able to publish with msbuild like this:

c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe "C:\...\UI.csproj" /p:DeployOnBuild=true /p:PublishProfile="C:\...\PublishProfiles\my_sample_PublishProfile_Foo.pubxml"  /p:VisualStudioVersion=11.0

Remember to run the batch file that contains this script with Administrator privileges.

Sirocco answered 9/7, 2014 at 14:31 Comment(2)
What is C:\...\UI.csproj here? Since a website has no *.csproj file I don't get how this is supposed to work without the generated website.publishproj file.Subrogate
The question here is specifically about "Website Project". In that case there is no .csproj file, but instead the .publishproj file is used for that, and it's created once you create a publish profile. The .csproj file is for standard web application projects.Rightminded

© 2022 - 2024 — McMap. All rights reserved.