With the release of VS2012 we have improved the command line publish experience. We’ve also made all the web publish related features available for VS2010 users in the Azure SDK.
The easies way to publish a project from the command line is to create a publish profile in VS and then use that. To create a publish profile in Visual Studio right click on the web project and select Publish. After that it will walk you though creating a publish profile. VS Web publish profile support the following publish methods.
- Web Deploy – The preferred method. You can publish to any host/server which has Web Deploy configured
- Web Deploy Package - Used to create a package which can be published offline at a later time
- File system - Used to publish to a local/network folder
- FTP - Used to publish to any FTP server
- FPSE – Used to publish to a server using Front Page Server Extensions
Command line publishing is only supported for Web Deploy, Web Deploy Package, and File System. If you think we should support command line scenarios for other publish methods the best thing to do would be to create a suggestion at http://aspnet.uservoice.com. If there is enough interest we may work on that support.
Let’s first take a look at how you can publish a simple Web project from the command line. I have created a simple Web Forms project and want to publish that. I’ve created a profile named SayedProfile. In order to publish this project I will execute the following command.
msbuild MyProject.csproj /p:DeployOnBuild=true /p:PublishProfile=
In this command you can see that I have passed in these properties;
- DeployOnBuild – when true the build process will be extended to perform a publish as well
- PublishProfile - name of the publish profile (you can also provide a full path to a .pubxml file)
- Password – Password value
- VisualStudioVersion – Special property see comments below
You may not have expected the VisualStudioVersion property here. This is a new property which was introduced with VS 2012. It is related to how VS 2010 and VS 2012 are able to share the same projects. Take a look at my previous blog post at http://sedodream.com/2012/08/19/VisualStudioProjectCompatabilityAndVisualStudioVersion.aspx. If you are building the project file, instead of the solution file then you should always set this property.
If you are publishing using the .sln file you can omit the VisualStudioVersion property. That property will be derived from the version of the solution file itself. Note that there is one big difference when publishing using the project or solution file. When you build an individual project the properties you pass in are given to that project alone. When you build from the command line using the solution file, the properties you have specified are passed to all the projects. So if you have multiple web projects in the same solution it would attempt to publish each of the web projects.
FYI in case you haven’t already heard I’m working on an update to my book. More info at msbuildbook.com
Sayed Ibrahim Hashimi | @SayedIHashimi
Comments are closed.