Dia
Dia

Reputation: 947

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?

Upvotes: 8

Views: 6236

Answers (1)

dimaaan
dimaaan

Reputation: 917

Try dotnet-publish-ssh.

It works like dotnet publish, but allows you to copy your 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

Upvotes: 4

Related Questions