Publish .net core MVC from visual studio to linux

2020-07-08 11:12发布

问题:

Can I edit a .Net Core MVC aplication in Visual Studio and deploy to Linux server (e.g. Ubuntu).

Are there any tutorials for this problem?

回答1:

You can check this page in the ASP.NET CORE documentation - https://docs.microsoft.com/en-us/aspnet/core/publishing/linuxproduction

A good example can also be found in this blog post from Scott Hanselman - https://www.hanselman.com/blog/PublishingAnASPNETCoreWebsiteToACheapLinuxVMHost.aspx

I currently use my own batch script to deploy which follows these steps:

  1. Publishes the app using dotnet publish command.
  2. Zips everything using Powershell.
  3. Copies the zip to the Linux machine using pscp - https://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter5.html
  4. Connects to the Linux machine using Windows Bash (you need Windows 10 Anniversary Update for this feature to be available).
  5. Calls the unzip command on the Linux machine - needs to be installed there first.
  6. Restarts the supervisor service on the Linux machine.


回答2:

I do not know how your can deploy from Visual Studio to Ubuntu server, but if you have access to the server (for instance with SSH) you can simply pull your code from a Git's repository, then compile, publish and run.