You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure ARM DSC:VS2017远程调试器安装与服务配置求助

我刚好之前在Service Fabric集群环境里配置过VS2017远程调试器的DSC脚本,碰到过和你一样的问题,给你整理了完整的解决方案,分成服务配置和防火墙规则两个核心部分:

一、配置VS2017远程调试器为自动启动服务

首先要确认VS2017远程调试器的服务名称是msvsmon150(你可以在节点上执行Get-Service | Where-Object DisplayName -like "*Remote Debugger*"验证)。如果安装后服务未自动注册,我们需要先通过脚本注册服务,再用DSC的Service资源确保它自动启动并运行:

Configuration ConfigureVSRemoteDebugger {
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node $AllNodes.NodeName {
        # 假设你已经用Package资源完成了远程工具的安装,这里依赖安装步骤
        Package VSRemoteToolsInstallation {
            Name            = "Microsoft Visual Studio 2017 Remote Debugger"
            Path            = "C:\Temp\vs_remotetools.exe"
            Arguments       = "/install /quiet /norestart"
            ProductId       = "{YOUR-PRODUCT-ID}" # 替换为VS2017远程工具的Product ID
            Ensure          = "Present"
        }

        # 如果服务未注册,执行msvsmon.exe的注册命令
        Script RegisterVSRemoteDebuggerService {
            GetScript = {
                @{
                    Result = (Get-Service -Name 'msvsmon150' -ErrorAction SilentlyContinue) -ne $null
                }
            }
            TestScript = {
                (Get-Service -Name 'msvsmon150' -ErrorAction SilentlyContinue) -ne $null
            }
            SetScript = {
                # 根据你的安装路径调整,这里是默认的x64路径
                $remoteDebuggerExe = "C:\Program Files\Microsoft Visual Studio 15.0\Common7\IDE\Remote Debugger\x64\msvsmon.exe"
                if (Test-Path $remoteDebuggerExe) {
                    & $remoteDebuggerExe /register
                    Write-Verbose "成功注册VS2017远程调试器服务"
                }
                else {
                    throw "VS2017远程调试器执行文件不存在,请检查安装路径"
                }
            }
            DependsOn = '[Package]VSRemoteToolsInstallation'
        }

        # 确保服务设置为自动启动并处于运行状态
        Service VSRemoteDebuggerService {
            Name        = 'msvsmon150'
            State       = 'Running'
            StartupType = 'Automatic'
            DependsOn   = '[Script]RegisterVSRemoteDebuggerService'
        }
    }
}
二、设置防火墙允许远程调试端口

VS2017远程调试器默认使用TCP端口4022,我们需要通过DSC配置入站防火墙规则来允许这个端口的流量。推荐使用NetworkingDsc模块的Firewall资源(比默认的PSDSC防火墙资源更可靠):

# 先确保安装NetworkingDsc模块
# Install-Module -Name NetworkingDsc -Force

Configuration ConfigureVSRemoteDebuggerFirewall {
    Import-DscResource -ModuleName NetworkingDsc

    Node $AllNodes.NodeName {
        Firewall VSRemoteDebuggerInboundRule {
            Name                  = 'VS2017RemoteDebugger_Inbound_TCP_4022'
            DisplayName           = 'Visual Studio 2017 Remote Debugger'
            Group                 = 'Visual Studio Remote Debugger'
            Ensure                = 'Present'
            Enabled               = 'True'
            Direction             = 'Inbound'
            Protocol              = 'TCP'
            LocalPort             = 4022
            RemoteAddress         = 'Any' # 可以根据安全需求限制为特定IP段,比如'192.168.1.0/24'
            Action                = 'Allow'
            DependsOn             = '[Service]VSRemoteDebuggerService'
        }
    }
}

关键注意事项

  • 安装路径验证:如果你的VS远程工具安装在非默认路径(比如x86版本),需要调整msvsmon.exe的路径为C:\Program Files (x86)\Microsoft Visual Studio 15.0\Common7\IDE\Remote Debugger\x86\msvsmon.exe。
  • 端口确认:如果修改过远程调试器的端口,需要同步调整防火墙规则中的LocalPort值。
  • Service Fabric节点权限:确保DSC运行账号有足够权限注册服务和修改防火墙规则(建议使用本地管理员权限)。

内容的提问来源于stack exchange,提问作者tonjohn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:54:34