8

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?

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

1 Comment

I'm not even sure how to install, use this add on in VS 2019. I couldn't find any documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.