Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build and publish C# .NET Web App via command line

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?

like image 520
user1094786 Avatar asked Jun 05 '14 14:06

user1094786


People also ask

What is difference between build and publish?

Build compiles the source code into a (hopefully) runnable application. Publish takes the results of the build, along with any needed third-party libraries and puts it somewhere for other people to run it.

Do I need to run dotnet build before publish?

You are right that dotnet publish automatically does everything dotnet build already does. In most cases - as in your scenario mentioned in the question - that means an additional dotnet build is not necessary. Do note that you can dotnet build a solution, but should only dotnet publish individual project files.

What does it mean to publish in Visual Studio?

Publishing creates the set of files that are needed to run your application. To deploy the files, copy them to the target machine.

What is .NET publish?

dotnet publish compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files to a directory. The output includes the following assets: Intermediate Language (IL) code in an assembly with a dll extension. A .


1 Answers

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

like image 173
TrevorBrooks Avatar answered Sep 18 '22 13:09

TrevorBrooks