14

I need to be able to generically and separately build and publish C# ASP.NET Web Applications. Ideally, I would like to use MSBuild to build the application, and if that succeeds, I would like to simply publish the site preferably solely with file copy.

Currently, I am able to build web application quite easily with MSBuild, but it is the publishing that is causing confusion. After the build, the binaries sit in the bin folder, but I am not sure what files to copy. What would be a good way to mimic the operations that VS's publish feature does, and still keeping everything generic?

2
  • Any deployment task is just wrapped in MSBuild arguments. Commented Jun 9, 2014 at 14:37
  • With .NET CORE 3.0 this is simplified, Checkout this post: stackoverflow.com/a/56710981/6441150 Commented Jun 21, 2019 at 22:14

2 Answers 2

27

You can invoke the Visual Studio web publish pipeline using the command line, check out this tutorial it shows you step by step how to do it:

Specifying the publish profile

You can specify the publish profile by name or by the full path to the .pubxml file, as shown in the following example:

msbuild C:\ContosoUniversity\ContosoUniversity.sln /p:DeployOnBuild=true /p:PublishProfile=C:\ContosoUniversity\ContosoUniversity\Properties\PublishProfiles\Test.pubxml

Web publish methods supported for command-line publishing

Three publish methods are supported for command line publishing:

  • MSDeploy - Publish by using Web Deploy.

  • Package - Publish by creating a Web Deploy Package. You have to install the package separately from the MSBuild command that creates it.

  • FileSystem - Publish by copying files to a specified folder.

http://www.asp.net/mvc/tutorials/deployment/visual-studio-web-deployment/command-line-deployment

Sign up to request clarification or add additional context in comments.

4 Comments

thank you! I was thinking about doing that but would ideally prefer something simpler like file copy, or would it then not be possible to keep it generic?
You can create a FileSystem publish profile and then use the PublishProfile switch the article shows how to do this. Look towards the bottom of the article.
I followed the tutorial's instructions for building a project and the publish didn't work.
I would start a new question since this is 3 years old.
0

The latest projects can be built by:

dotnet build MyWebsite.sln

For more info please refer the microsoft docs: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-build

Note: Old ASP.NET projects are not supported. Please use MsBuild instead https://stackoverflow.com/a/24063993/1143349.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.