0
votes

I'm creating a Service Fabric cluster for a dev environment which requires the Visual Studio 2017 Remote Debugger to be installed and running as a service on each node using Powershell DSC.

Our DSC script successfully copies the vs2017 remote tools installer and does the unattended install but we are struggling to get it running as a service and with the correct firewall settings.

1

1 Answers

0
votes

Here is what we ended up going with:

# Download and configure Chocolaty
cChocoInstaller InstallChoco 
{ 
    InstallDir = "C:\choco" 
}

# Download and install VS2017 Remote Debugger
cChocoPackageInstaller InstallRemoteDebugger
{            
    Name = "visualstudio2017-remotetools" 
    Version = "15.0.26430.2" 
    Source = “https://github.com/chocolatey/chocolatey-coreteampackages/tree/master/manual/visualstudio2017-remotetools” 
    DependsOn = "[cChocoInstaller]installChoco"
}

# Install the remote debugger and run as a service
Script ConfigureRemoteDebugger {
    GetScript  = { @{ Result = "" } }
    TestScript = { 

        $msvsmonPathx64 = 'C:\Program Files\Microsoft Visual Studio 15.0\Common7\IDE\Remote Debugger\x64\msvsmon.exe'
        $serviceName = "msvsmon150"
        $result = $true

        # Validate the VS2017 Remote Debugger is installed to the harddrive
        $result = $result -and (Test-Path $msvsmonPathx64)

        # Verify the service exists and is running
        if ($service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue) {
            if ($service.Status -eq "Running") {
                $result = $result -and $true
            }
            else {
                $result = $result -and $false
            }
        }
        else {
            $result = $result -and $false
        }

        return $result
    }
    SetScript  = 
    {
        # Run as service
        $startDebugger = $true
        $remoteDebugExe = "`"C:\Program Files\Microsoft Visual Studio 15.0\Common7\IDE\Remote Debugger\x64\rdbgservice.exe`" msvsmon150"
        $serviceName = "msvsmon150"
        $serviceDisplayName = "Visual Studio 2017 Remote Debugger"
        $serviceDescription = "Allows members of the Administrators group to remotely debug server applications using Visual Studio. Use the Visual Studio Remote Debugging Configuration Wizard to enable this service."

        if (!(Get-Service -Name msvsmon150 -ErrorAction SilentlyContinue)) {
            New-Service -Name $serviceName -BinaryPathName $remoteDebugExe -DisplayName $serviceDisplayName -Description $serviceDescription 
        }

        if ($startDebugger -eq $false) {
            Set-Service -Name $serviceName -StartupType Manual
        }
        else {
            Set-Service -Name $serviceName -StartupType Automatic
            Start-Service -Name $serviceName
        }
    }
    Credential = $serviceAccountCredential
    DependsOn  = "[cChocoPackageInstaller]InstallRemoteDebugger"
}

Note: Your DSC will likely need to configure the firewall to allow the Remote Debugger otherwise you will not be able to connect.

Big shoutout to Chocolatey for making the download+install process so easy.