If you’re like me, you sometimes have to make up some quick C# code. This is pretty trivial to test against other machines when using PowerShell, thanks to the likes of
PowerShell Sessions. However, what about doing remote debugging via C# or non-scripting languages?
Visual Studio has great debugging guidance here. The documentation even includes a reference to xcopy and robocopy, which help you get the files on the remote machine. But it stops there.
This is a pain if you do it manually–the folder structure of the files you want to remotely debug need to match perfectly the destination folder structure.
So… for those who don’t want to search to much on the Internet, here is a quick xcopy command, ensuring all folders are recursively kept in order and sync’d across machines.
param( #source path # source path [Parameter(Mandatory=$true)] [string] $SourcePath, # destination IP [Parameter(Mandatory=$true)] [string] $DestinationIp, # remote user [Parameter(Mandatory = $true)] [string] $remoteUser, # remote user domain [Parameter(Mandatory = $false)] [string] $remoteUserDomain, # remote user password [Parameter(Mandatory=$true)] [string] $remoteUserPass ) $homedir = Resolve-Path $SourcePath $destIP = $DestinationIp $remoteUser = $remoteUser $remoteUserDomain = $remoteUserDomain $remoteUserPassword = $remoteUserPass $homedirModified = $homedir.ToString() -split ':\\' $drive = $homedirModified $netuseUri = "\\$destIP\IPC`$" $destString = "\\$destIP\$drive`$\$($homedirModified)" # ensure we use proper network cred net use $netuseUri /user:$remoteUserDomain\$remoteUser $remoteUserPassword # use robocopy robocopy $homedir $destString /mir /r:1 /w:1 # remove network cred net use $netuseUri /D
Robocopy is powerful but sometimes too complex. Here, we only use the options we need. You can then repeat this process everytime you make changes, and it will mirror your source to your destination. This includes even deleting files in the Destination that aren’t in the source (
/mir; mirror mode).
Happy hunting (and developing)!