简体   繁体   中英

Deploy .net core app to linux in visual studio?

I am building a .net core app in Visual Studio 2017. I would like to automate my the publishing process to a linux machine.

This is my current process:

  1. In Visual Studio, click Publish tab, select Publish
  2. Open WinSCP , login to target linux machine
  3. Open the folder solution\\myapp\\bin\\Release\\netcoreapp2.2\\publish\\
  4. CTRL + A select all in publish folder, CTRL + C copy all the files, then CTRL + V paste in WinSCP target directory
  5. Open PuTTY , login to target linux machine, restart the app using dotnet myapp.dll

Could I automate these steps when publishing from Visual Studio?

Try dotnet-publish-ssh .

It works like dotnet publish, but allows you to copy you app over SSH to your target linux machine.

Here is my config:

dotnet publish-ssh --ssh-host <host> --ssh-user <user> --ssh-password <pass> --ssh-path /var/<myapp> --configuration Release --framework netcoreapp3.1 --runtime linux-x64 --self-contained false /p:PublishSingleFile=true

To restart the app you may try powershell with Posh-SSH module:

Import-Module Posh-SSH
$serverAddress = "host addr"
$user = "user"
$pass = ConvertTo-SecureString "pass" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($user, $pass)
$launchFolder = "/var/<myapp>"
$sshSession = New-SSHSession -ComputerName $serverAddress -Credential $creds -ErrorAction Stop
Invoke-SSHCommand -SSHSession $sshSession -Command "<your restart command>"
Remove-SSHSession -SSHSession $sshSession

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM