Hac*_*ám 6 linux publish visual-studio .net-core
我可以在Visual Studio中编辑.Net Core MVC应用程序并部署到Linux服务器(例如Ubuntu).
有没有针对这个问题的教程?
您可以在 ASP.NET CORE 文档中查看此页面 - https://docs.microsoft.com/en-us/aspnet/core/publishing/linuxproduction
一个很好的例子也可以在 Scott Hanselman 的这篇博文中找到 - https://www.hanselman.com/blog/PublishingAnASPNETCoreWebsiteToA CheapLinuxVMHost.aspx
我目前使用自己的批处理脚本进行部署,步骤如下:
编辑: 我添加了我按照Andrew Basarab 的要求发布原始答案时使用的脚本版本。考虑到我当时糟糕的脚本知识,我确信它需要一些重构。请谨慎使用:
@echo off
set PrivateKeyLocation="C:\fakepath\fakefile.ppk {private key for connecting to the remote Linux machine}"
set CertificateFileLocation="/mnt/c/fakepath/fakefile.pem {same key used to execute remote bash commands from my Windows machine}"
for %%* in (.) do set CurrentDirName=%%~nx*
set OutputFolder="%tmp%\%CurrentDirName%"
set OutputZipFile="%tmp%\%CurrentDirName%.zip"
set RemoteHost="ubuntu@54.142.181.122 {remote host address}"
set RemoteLocation="/home/ubuntu {the location to copy the output to}"
dotnet publish -o "%OutputFolder%"
powershell -command "& {&'Compress-Archive' -Path %OutputFolder% -DestinationPath %OutputZipFile%}"
rmdir /s /q %OutputFolder%
pscp -i %PrivateKeyLocation% -pw {private key password} %OutputZipFile% %RemoteHost%:%RemoteLocation%
del /q %OutputZipFile%
bash -c "ssh -i %CertificateFileLocation% %RemoteHost% 'sudo rm -rf %CurrentDirName% ; unzip %CurrentDirName%.zip ; rm -r %CurrentDirName%.zip ; sudo service supervisor restart'"
Run Code Online (Sandbox Code Playgroud)
一些工具和服务需要在两台机器上安装。请参阅 Scott Hanselman 的上述帖子。
我不知道如何从Visual Studio 部署到 Ubuntu 服务器,但如果您有权访问服务器(例如使用 SSH),您可以简单地从 Git 存储库中提取代码,然后编译、发布和运行。
| 归档时间: |
|
| 查看次数: |
3041 次 |
| 最近记录: |