• This repository has been archived on 13/May/2022
  • Stars
    star
    141
  • Rank 259,971 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

This project has been archived

dotnet-sshdeploy

NuGet Analytics Build Status Build status NuGet version

Please star this project if you find it useful!

A dotnet CLI command 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:

  • dotnet-sshdeploy monitor - Watches changes on a single file, if this event is raised then it proceeds to send the specified source path files over SSH
  • dotnet-sshdeploy push - Single-use command that transfers files over SSH

Installation

We are using the brand new implementation of the global tool in .NET Core Apps 2.1+. Now you can easily download the package by running the next command

dotnet tool install -g dotnet-sshdeploy

Custom installation

If you download the project and want to test installing your own version of the project you need to pack and then install the nuget

// In the root of your project run
dotnet pack

// Run the following command where you nupkg was created
dotnet tool install -g dotnet-sshdeploy --add-source ./

Update

To update ssh-deploy to the latest version, use the dotnet tool update command

dotnet tool update -g dotnet-sshdeploy

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:
<PropertyGroup>
    <SshDeployHost>192.168.2.194</SshDeployHost>
    <SshDeployClean />
    <SshDeployTargetPath>/home/pi/libfprint-cs</SshDeployTargetPath>
    <SshDeployUsername>pi</SshDeployUsername>
    <SshDeployPassword>raspberry</SshDeployPassword>
    <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
</PropertyGroup>
  1. We need a post build event as well:
<Target Condition="$(BuildingInsideSshDeploy) ==''" Name="PostBuild" AfterTargets="PostBuildEvent">
   <Exec Command="cd $(ProjectDir)" />
   <Exec Command="dotnet-sshdeploy push" />
</Target>

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

  • Be sure you are using ' / ' with RemoteTargetPath otherwise it will not work.
  • 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
  • If no RuntimeIdentifier is provided a Framework-dependent deployment will be created otherwise a Self-contained deployment will
  • The command needs to be excuted in the same folder as the csproj

If your project happens to target multiple runtimes, i.e. win-x64 and linux-arm, then sshdeploy does not necessarily know which binaries to deploy. Also, you might want to control that i.e. only the linux-arm build should be automatically deployed. In this case, you can change the post build event and add an additional condition to the target (only run on builds for linux), and also pass the desired runtime identifier to the actual deployment call as follows:

<Target Condition="$(BuildingInsideSshDeploy) == '' and $(RuntimeIdentifier) == 'linux-arm'" Name="PostBuild" AfterTargets="PostBuildEvent">
   <Exec Command="cd $(ProjectDir)" />
   <Exec Command="dotnet-sshdeploy push -r $(RuntimeIdentifier)" />
</Target>

Monitor

  1. Go to your Visual Studio Solution (the one you intend to continuously 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:
  • 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.
  1. Edit your csproj file and add:
    <RemoteHost>192.168.2.194</RemoteHost>
    <SourcePath>C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\bin\Debug</SourcePath>
    <RemoteTargetPath>/home/pi/libfprint-cs</RemoteTargetPath>
    <RemoteUsername>pi</RemoteUsername>
    <RemotePassword>raspberry</RemotePassword>
  1. Execute
dotnet-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/>
-x, --execute <SshDeployExecutePermission>

Old school way

Push

  1. Navigate to your project folder where the csproj file resides. Example:
cd C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\
  1. Execute this command with some arguments. Here's a simple example:
dotnet-sshdeploy push -f netcoreapp2.0 -t "/home/pi/libfprint-cs" -h 192.168.2.194
  • 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)
  • 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:
  • 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.
  1. Open a Command Prompt (Start, Run, cmd, [Enter Key])
  2. Navigate to your project folder where the csproj file resides
  • Example: cd "C:\projects\Unosquare.Labs.RasPiConsole\Unosquare.Labs.RasPiConsole\"
  1. Run this tool with some arguments. Here is an example so you can get started quickly.
    dotnet-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
  • 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.
  • Note that there are many more arguments you can use. Simply issue
dotnet-sshdeploy monitor

This will get you all the options you can use.

  • If all goes well you will see output similar to this:
SSH Deployment Tool [Version 0.3.1.0]
(c)2015 - 2017 Unosquare SA de CV. All Rights Reserved.
For additional help, please visit https://github.com/unosquare/sshdeploy

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 SSH.
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!
  1. Now 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.
  • Every time you rebuild your project, it will be automatically deployed!

  • In 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.

  • Here's a good example of using pre and post commands to acocmplish the above: dotnet-sshdeploy monitor -s "C:\projects\libfprint-cs\trunk\Unosquare.Labs.LibFprint.Tests\bin\Debug" -t "/home/pi/libfprint-cs" -h 192.168.2.194 --pre "pgrep -f 'Unosquare.Labs.LibFprint.Tests.exe' | xargs -r kill" --post "mono /home/pi/libfprint-cs/Unosquare.Labs.LibFprint.Tests.exe" --clean False

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 ✔️
-s --source The source path for the files to transfer. ✔️
-t --target The target path of the files to transfer. ✔️
--pre Command to execute prior file transfer to target.
--post Command to execute after file transfer to target.
--clean Deletes all files and folders on the target before pushing the new files True
--exclude a pipe (|) separated list of file suffixes to ignore while deploying. .ready|.vshost.exe|.vshost.exe.config
-v --verbose Add this option to print messages to standard error and standard output streams. True
-h --host Hostname or IP Address of the target. -- Must be running an SSH server. ✔️
-p --port Port on which SSH is running. 22
-u --username The username under which the connection will be established. pi
-w --password The password for the given username. raspberry
-l --legacy Monitor files using legacy method False

Push Mode

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

Special Thanks

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

More Repositories

1

embedio

A tiny, cross-platform, module based web server for .NET
C#
1,460
star
2

ffmediaelement

FFME: The Advanced WPF MediaElement (based on FFmpeg)
C#
1,172
star
3

passcore

A self-service password management tool for Active Directory
C#
1,031
star
4

raspberryio

The Raspberry Pi's IO Functionality in an easy-to-use API for Mono/.NET/C#
C#
673
star
5

swan

Swan stands for Stuff We All Need. Unosquare's collection of C# extension methods and classes.
C#
262
star
6

tubular-react

Material UI table with local or remote data-source. Featuring filtering, sorting, free-text search, export to CSV locally, and aggregations.
TypeScript
205
star
7

wiringpi-dotnet

Provides complete managed access to the popular wiringpi C library
C#
68
star
8

litelib

A cool little wrapper in Entity Framework style for SQLite based on Dapper
C#
63
star
9

pigpio-dotnet

Provides complete managed access to the popular pigpio C library
C
61
star
10

embedio-extras

Additional Modules showing how to extend EmbedIO.
C#
44
star
11

tubular

A set of AngularJS directives designed to rapidly build modern web applications
JavaScript
44
star
12

uno-react

Common functions, HOCs and hooks for React.
TypeScript
28
star
13

swan-aspnetcore

SWAN ASP.NET Core
C#
28
star
14

uno-material-ui

Components and extensions for Material UI
TypeScript
25
star
15

libfprint-cs

The long-awaited C# (.net/mono) wrapper for the great fprint library
C#
20
star
16

best-practices

Unosquare Labs Best Practices
JavaScript
19
star
17

tubular-dotnet

Tubular .NET Library
C#
18
star
18

ffplaydotnet

A port of FFmpeg's FFplay.c
C#
16
star
19

embedio-cli

EmbedIO CLI - .NET Core Global tool
C#
13
star
20

tubular2

Tubular for Angular 7
TypeScript
13
star
21

ef-enterpriseextensions

EntityFramework.EnterpriseExtensions Library
C#
12
star
22

sparkfunfingerprint

SparkFun Fingerprint Reader Interfacing Library for .NET Framework and .NET Core
C#
11
star
23

tenantcore

TenantCore, OWIN multitenancy
C#
10
star
24

wsfingerprint

WaveShare Fingerprint Reader Interfacing Library for .NET
C#
10
star
25

uno-js

Unosquare Typescript/JavaScript Library
TypeScript
10
star
26

tubular-common

Tubular Common Models and Data Transformer
TypeScript
10
star
27

ledemotion

LED Emotion
JavaScript
10
star
28

tubular-aspnet-core-boilerplate

Tubular ASP.NET Core Boilerplate
HTML
8
star
29

tubular-nodejs

Tubular Node.js backend
JavaScript
8
star
30

tubular-boilerplate-csharp

Tubular Boilerplate C#
JavaScript
7
star
31

unosquare.github.io

Main GitHub Pages repository
HTML
7
star
32

pocodata

The no-frills micro ORM for SQL Server
C#
7
star
33

redminetime

A Redmine time entries logger for Windows
C#
6
star
34

entityframework-specification

Unosquare EntityFramework Specification
C#
6
star
35

tubular-boilerplate

Tubular Directives Boilerplate (includes AngularJS and Bootstrap)
HTML
6
star
36

tsrelay

TinySine USB/Wireless Relay Module TOSR1x - Interfacing Library for .NET
C#
5
star
37

unolabs-pi

UnoLabs Raspberry Pi Demo
JavaScript
5
star
38

uno-dashboard-ux

Unosquare Dashboard UX/UI Components
TypeScript
4
star
39

tubular-fabric

Tubular for Office UI Fabric
TypeScript
3
star
40

.github

2
star
41

tubular-react-common

Tubular React Common functions and hooks
TypeScript
2
star
42

eslint-config-unosquare

Eslint Config Unosquare
JavaScript
1
star
43

swan-ldap

SWAN LDAP Client
C#
1
star