Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MSBuild.exe to "Publish" a ASP.NET MVC 4 project with the cmd line

I'm looking for a command to run against the MSBuild.exe that just takes a MVC 4 project and publishes it to a given directory.

For example,

MSBuild <solution>/<project>.csproj -publish -output=c:/folder 

This is obviously incorrect syntax. I'm trying to simplify my question.

This question talks of a build XML, but I'm not trying to do anything with that much detail.

I'm simply trying to do a deploy.

Further down in that question, someone speaks of "MSDeploy". I can look into that, but is it the only option? I do not have the ability to install web deploy on the server. In which case, all I really need to do is "Publish" and send the contents of the published project to a given directory on the server/file-system.

Does anyone have a one liner I can use?

Do I have to use MSDeploy?

Does MSDeploy require web deploy to be installed on the server?

Doesn't setting up web deploy on the server require setting up some ports, permissions, and installing some IIS add-ons?

I'd love to just execute something simple.

like image 888
Erik5388 Avatar asked Dec 17 '12 18:12

Erik5388


People also ask

How do I create a project using MSBuild command line?

To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.

How do I add MSBuild exe to path?

Click on System and Security and then on System. In the left pane, click on Advanced system settings. At the very bottom of the pop up, click on Environment Variables. Edit the Path variable and append the folder's path that contains the MSBuild.exe to it (e.g., ;C:\Windows\Microsoft.NET\Framework64\v4.


1 Answers

In VS 2012 (as well as the publish updates available in the Azure SDK for VS 2010) we have simplified command line publishing for web projects. We have done that by using Publish Profiles.

In VS for a web project you can create a publish profile using the publish dialog. When you create that profile it is automatically stored in your project under Properties\PublishProfiles. You can use the created profile to publish from the command line with a command line the following.

msbuild mysln.sln /p:DeployOnBuild=true /p:PublishProfile=<profile-name> 

If you want to store the publish profile (.pubxml file) in some other location you can pass in the path to the PublishProfile.

Publish profiles are MSBuild files. If you need to customize the publish process you can do so directly inside of the .pubxml file.

If your end goal is to pass in properties from the command line. I would recommend the following. Create a sample publish profile in VS. Inspect that publish profile to determine what MSBuild properties you need to pass in on the command line. FYI not all publish method support command line publishing (i.e. FTP/FPSE).

FYI if you are building the .csproj/.vbproj instead of the .sln and you are using VS 2012 you should also pass in /p:VisualStudioVersion=11.0. For more details as to why see http://sedodream.com/2012/08/19/VisualStudioProjectCompatabilityAndVisualStudioVersion.aspx.

like image 72
Sayed Ibrahim Hashimi Avatar answered Oct 11 '22 22:10

Sayed Ibrahim Hashimi