将 ASP.NET Core 从 Visual Studio 发布到 Linux

编程入门 行业动态 更新时间:2024-10-10 21:28:14
本文介绍了将 ASP.NET Core 从 Visual Studio 发布到 Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我可以在 Visual Studio 中编辑 ASP.NET Core 应用程序并部署到 Linux 服务器吗(例如,Ubuntu)?

Can I edit a ASP.NET Core application in Visual Studio and deploy to Linux server (e.g., Ubuntu)?

有针对这个问题的教程吗?

Is there a tutorial for this problem?

推荐答案

您可以在 ASP.NET CORE 文档中查看此页面 - docs.microsoft/en-us/aspnet/core/publishing/linuxproduction

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

在 Scott Hanselman 的这篇博文中也可以找到一个很好的例子 - www.hanselman/blog/PublishingAnASPNETCoreWebsiteToACheapLinuxVMHost.aspx

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

我目前使用自己的批处理脚本进行部署,具体步骤如下:

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

  • 使用 dotnet publish 命令发布应用.
  • 使用 Powershell 压缩所有内容.
  • 使用 pscp 将 zip 复制到 Linux 机器 - the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter5.html
  • 使用 Windows Bash 连接到 Linux 计算机(您需要 Windows 10 周年更新才能使用此功能).
  • 在 Linux 机器上调用 unzip 命令 - 需要先在那里安装.
  • 重新启动 Linux 机器上的主管服务.
  • 我已经按照 Andrew Basarab 的要求添加了我在发布原始答案时使用的脚本版本.考虑到我当时糟糕的脚本知识,我确信它需要一些重构.请谨慎使用:

    I have added the version of my script which I used when I posted my original answer as requested by Andrew Basarab. I'm sure it needs some refactoring considering my poor scripting knowledge back then. Please use with caution:

    @echo off set PrivateKeyLocation="C:fakepathfakefile.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'"

    一些工具和服务需要在两台机器上安装.请参阅 Scott Hanselman 的上述帖子.

    Some tools and services need to be installed on both machines. Please refer to the aforementioned post by Scott Hanselman.

    更多推荐

    将 ASP.NET Core 从 Visual Studio 发布到 Linux

    本文发布于:2023-06-11 00:11:17,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/621971.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:Core   NET   ASP   Linux   Studio

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!