unosquare/sshdeploy

Name: sshdeploy

Owner: Unosquare Labs

Description: A command-line tool that enables quick build and run deployments over SSH.

Created: 2015-05-18 15:18:17.0

Updated: 2018-05-23 21:54:38.0

Pushed: 2018-05-23 21:54:37.0

Homepage: http://unosquare.github.io/

Size: 200

Language: C#

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

dotnet-sshdeploy

NuGet Analytics Build Status Build status NuGet version

:star: Please star this project if you find it useful!

A dotnet CLI extension that enables quick deployments over SSH. This program was specifically designed to streamline .NET application development for the Raspberry Pi running Raspbian.

If you came here looking for our old version of SSHDeploy please click here, otherwise you are in the right place

The following commands are currently available:

Installation

As of now, CLI does not allow command line installation so you'll need to modify your csproj manually.

<ItemGroup>
 <DotNetCliToolReference Include="dotnet-sshdeploy" Version="0.1.6-r1" />
</ItemGroup>
Usage

There are two ways of passing arguments: the old school way using the cli and our approach using the csproj file.

Using the csproj file
Push
  1. Edit your csproj file and add:

    pertyGroup>
    DeployHost>192.168.2.194</SshDeployHost>
    DeployClean />
    DeployTargetPath>/home/pi/libfprint-cs</SshDeployTargetPath>
    DeployUsername>pi</SshDeployUsername>
    DeployPassword>raspberry</SshDeployPassword>
    PostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
    opertyGroup>
    
  2. We need a post build event as well:

    get Condition="$(BuildingInsideSshDeploy) ==''" Name="PostBuild" AfterTargets="PostBuildEvent">
    c Command="cd $(ProjectDir)" />
    c Command="dotnet sshdeploy push" />
    rget>
    

    Voilą! sshdeploy finds the necessary arguments provided using proper xml tags and deploys after a successful build

  3. Be sure you are using ' / ' with RemoteTargetPath otherwise it will not work.

  4. You MUST use the property BuildingInsideSshDeploy to make sure this event will not be executed within sshdeploy's build method to avoid an infinite loop

  5. If no RuntimeIdentifier is provided a Framework-dependent deployment will be created otherwise a Self-contained deployment will

    Monitor
  6. Go to your Visual Studio Solution (the one you intend to continuously deploy to the Raspberry Pi).

  7. Right-click on the project and click on the menu item “Properties”

  8. Go to the “Build Events” tab, and under Post-build events, enter the following:

  9. echo %DATE% %TIME% >> "$(TargetDir)sshdeploy.ready" *This simply writes the date and time to the sshdeploy.ready file. Whenever this file CHANGES, the deployment tool will perform a deployment.

  10. Edit your csproj file and add:

    oteHost>192.168.2.194</RemoteHost>
    rcePath>C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\bin\Debug</SourcePath>
    oteTargetPath>/home/pi/libfprint-cs</RemoteTargetPath>
    oteUsername>pi</RemoteUsername>
    otePassword>raspberry</RemotePassword>
    
  11. Execute

    et sshdeploy monitor
    

    FYI: Arguments passed using the csproj file will not override the ones provided using the cli

    XML Tags

    Heres a complete list of arguments with their corresponding XML tag.

| Args | XML Tag | | :————–: | :——————:| | -m,–monitor | <SshDeployMonitorFile> | | -f,–framework | <TargetFramework> | | -r,–runtime | <RuntimeIdentifier> | | -s, –source | <SshDeploySourcePath> | | -t,–target |<SshDeployTargetPath> | | –pre | <SshDeployPreCommand> | | –post | <SshDeployPostCommand> | | –clean | <SshDeployClean/> | | –exclude | <SshDeployExclude> | | -v,–verbose | <SshDeployVerbose/> | | -h,–host | <SshDeployHost> | | -p,–port | <SshDeployPort> | | -u,–username | <SshDeployUsername> | | -w,–password | <SshDeployPassword> | | -l,–legacy | <SshDeployLegacy/> |

Old school way
Push
  1. Navigate to your project folder where the csproj file resides. Example:
    :\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\
    
  2. Execute this command with some arguments. Here's a simple example:
    et sshdeploy push -f netcoreapp2.0 -t "/home/pi/libfprint-cs" -h 192.168.2.194
    
  3. In the command shown above :
    • -f refers to the source framework
    • -t refers to the target path
    • -h refers to the host (IP address of the Raspberry Pi)
  4. For a detailed list of all the arguments available please see below or execute dotnet sshdeploy push
Monitor

The following steps outline a continuous deployment of a Visual Studio solution to a Raspberry Pi running the default Raspbian SSH daemon.

  1. Go to your Visual Studio Solution (the one you intend to continously deploy to the Raspberry Pi).

  2. Right-click on the project and click on the menu item “Properties”

  3. Go to the “Build Events” tab, and under Post-build events, enter the following:

  4. echo %DATE% %TIME% >> "$(TargetDir)sshdeploy.ready" *This simply writes the date and time to the sshdeploy.ready file. Whenever this file CHANGES, the deployment tool will perform a deployment.

  5. Open a Command Prompt (Start, Run, cmd, [Enter Key])

  6. Navigate to your project folder where the csproj file resides

  7. Example:cd "C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\"

  8. Run this tool with some arguments. Here is an example so you can get started quickly.

    et sshdeploy monitor -s "C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\bin\Debug" -t "/home/pi/target" -h 192.168.2.194 -u pi -w raspberry
    
  9. In the above command,

    • -s refers to the source path of the files to transfer.
    • t refers to the full path of the target directory.
    • -h refers to the host (IP address of the Raspberry Pi).
    • -u refers to the login.
    • -w refers to the password.
  10. Note that there are many more arguments you can use. Simply issue

    et sshdeploy monitor
    

    This will get you all the options you can use.

  11. If all goes well you will see output similar to this:

    Deployment Tool [Version 1.0.0.0]
    2015 Unosquare SA de CV. All Rights Reserved.
    

Monitor mode starting Monitor parameters follow:

Monitor File    C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\bin\Debug\sshdeploy.ready
Source Path     C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\bin\Debug
Excluded Files  .ready|.vshost.exe|.vshost.exe.config
Target Address  192.168.2.194:22
Username        pi
Target Path     /home/pi/target
Clean Target    YES
Pre Deployment
Post Deployment

Connecting to host 192.168.2.194:22 via SFTP. File System Monitor is now running. Writing a new monitor file will trigger a new deployment. Remember: Press Q to quit. Ground Control to Major Tom: Have a nice trip in space!

ow go back to your Visual Studio Solution, right click on the project, a select "Rebuild". You should see the output in the command line similar to the following:
 Starting deployment ID 1 - Sunday, June 14, 2015 10:16:20 PM
 Cleaning Target Path '/home/pi/target'
 Deploying 3 files.
 Finished deployment in 0.88 seconds.
ery time you rebuild your project, it will be automatically deployed!

n order to make this tool much more useful, we need to take advantage of the pre and post commands. The idea is to find the process and kill it if it is currently running on the pre-command, and run the process once the deployment has been completed using the post-command argument. The hope is that this will make the deploy, run, and debug cycle, much less tedious for a .NET developer using a Raspberry Pi.*

re's a good example of using pre and post commands to acocmplish the above:
References
Monitor Mode

|Short Argument | Long Argument | Description | Default | Required| |:—–: | :———–: | :—————————————————-: | :———–:| :———–:| | -m | –monitor | The path to the file used as a signal that the files are ready to be deployed. Once the deploymetn is completed,the file is deleted. | sshdeploy.ready | :heavy_check_mark:| | -s | –source | The source path for the files to transfer | |:heavy_check_mark:| | -t | –target | The target path of the files to transfer | |:heavy_check_mark:| | | –pre | Command to execute prior file transfer to target | | :x: | | |–post | Command to execute after file transfer to target | | :x: | | –clean | Deletes all files and folders on the target before pushing the new files | True |:x: | | | –exclude | a pipe (\|) separated list of file suffixes to ignore while deploying.|.ready\|.vshost.exe\|.vshost.exe.config |:x:| | -v | –verbose |Add this option to print messages to standard error and standard output streams. | True | :x:| | -h | –host | Hostname or IP Address of the target. – Must be running an SSH server. | |:heavy_check_mark:| | -p | –port | Port on which SSH is running. | 22 | :x: | | -u |–username | The username under which the connection will be established. |pi | :x: | | -w | –password |The password for the given username. | raspberry | :x: | | -l | –legacy | Monitor files using legacy method | False | :x: |

Push Mode

|Short Argument | Long Argument | Description | Default | Required | |:————-:| :———–: | :—————————————————-: | :———–:| :———–:| | -c |–configuration| Target configuration. | Debug | :x: | | -f |–framework |The source framework | |:heavy_check_mark:|
| | –pre | Command to execute prior file transfer to target | | :x: | | |–post | Command to execute after file transfer to target | | :x: | | –clean | Deletes all files and folders on the target before pushing the new files | True |:x: | | | –exclude | a pipe (\|) separated list of file suffixes to ignore while deploying.|.ready\|.vshost.exe\|.vshost.exe.config |:x:| | -v | –verbose |Add this option to print messages to standard error and standard output streams. | True | :x:| | -h | –host | Hostname or IP Address of the target. – Must be running an SSH server. | |:heavy_check_mark:| | -p | –port | Port on which SSH is running. | 22 | :x: | | -u |–username | The username under which the connection will be established. |pi | :x: | | -w | –password |The password for the given username. | raspberry | :x: |

Special Thanks

This code uses the very cool Renci's SSH.NET library and our awesome SWAN library.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.