自托管Github Runner执行UWP vstest遇权限拒绝,托管Runner正常
在Windows 10上搭建自托管Runner执行UWP测试时遇到权限异常:
- 本地通过RDC连接,在PowerShell中直接运行
vstest.console.exe,测试可正常执行 - 用GitHub Actions调用自托管Runner执行完全相同的命令,抛出
UnauthorizedAccessException: Access is denied.错误 - 改用管理员账号配置Runner后,问题依然存在
- 使用GitHub托管的
windows-latestRunner执行相同Action,测试完全正常
推测问题与Runner权限及UWP测试需安装包后以应用形式执行的特性相关,完整错误日志如下:
'UnitTesterUWP_1.0.0.0_x64__gwkdyh6xmv8h8'. Attempting to launch app with app user model Id 'UnitTesterUWP_gwkdyh6xmv8h8!vstest.executionengine.universal.App' and arguments '--port 57663 --endpoint 127.0.0.1:057663 --role client --parentprocessid 32412 --local-path "C:\actions-runner\_work\MY_App\MY_App\repoMY_App\x64\Release\MY_UNITTEST_WIN_UWP" --datacollectionport 57662 --telemetryoptedin false'. Deploy: END (Success, 0:00:00,935) UnauthorizedAccessException: Access is denied. Access is denied. at Microsoft.VisualStudio.Deployment.IPackageDebugSettings.EnableDebugging(String packageFullName, String debuggerCommandLine, String environment) App activation failed. at Microsoft.VisualStudio.Deployment.LocalAppActivationDriver.LaunchAppLocally(String appUserModelId, String packageFullName, String launchArgs, String architecture) at Microsoft.VisualStudio.Deployment.LocalAppActivationDriver.Microsoft.VisualStudio.Deployment.IAppActivationDriver.LaunchAppAsync(String appUserModelId, String packageFullName, String launchArgs, String target, String architecture) at Microsoft.VisualStudio.Deployment.Service.<Microsoft-UniversalApps-Deployment-IAppLauncher-LaunchAppAsync>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.UwpTestHostRuntimeProvider.Deployer.<Microsoft-VisualStudio-UwpTestHostRuntimeProvider-IDeployer-ActivateAsync>d__53.MoveNext() Failed to initialize client proxy: could not connect to test process. Closing app with package full name 'UnitTesterUWP_1.0.0.0_x64__gwkdyh6xmv8h8'. UnauthorizedAccessException: Access is denied. Access is denied. Closing the app failed. at Microsoft.VisualStudio.Deployment.IPackageDebugSettings.TerminateAllProcesses(String packageFullName) at Microsoft.VisualStudio.Deployment.LocalAppActivationDriver.Microsoft.VisualStudio.Deployment.IAppActivationDriver.CloseAppAsync(String appUserModelId, String packageFullName, String target, String architecture) at Microsoft.VisualStudio.Deployment.Service.<Microsoft-UniversalApps-Deployment-IAppLauncher-CloseAppAsync>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.UwpTestHostRuntimeProvider.Deployer.<Microsoft-VisualStudio-UwpTestHostRuntimeProvider-IDeployer-CloseAppAsync>d__54.MoveNext() Test Run Aborted.
可能的原因及解决方法
1. 自托管Runner的会话交互权限限制
GitHub自托管Runner默认以非交互式服务运行,而UWP应用激活需要桌面会话交互权限——这是它与GitHub托管Runner的核心差异(托管Runner在交互式会话中运行)。
- 解决步骤:
- 停止当前Runner服务:打开服务管理器,找到
GitHub Actions Runner服务并停止 - 卸载服务:在Runner安装目录执行
.\svc uninstall - 以交互式方式启动Runner:打开管理员权限的PowerShell,进入Runner目录执行
.\run.cmd,保持窗口打开;可配合Windows任务计划设置开机自动启动交互式会话
- 停止当前Runner服务:打开服务管理器,找到
2. UWP调试权限缺失
错误日志显示调用IPackageDebugSettings.EnableDebugging时权限不足,Runner账号可能没有UWP调试权限。
- 解决步骤:
- 打开本地组策略编辑器(执行
gpedit.msc) - 导航至
计算机配置>Windows设置>安全设置>本地策略>用户权限分配 - 找到
调试程序权限,添加Runner运行账号 - 重启Runner或机器使设置生效
- 打开本地组策略编辑器(执行
3. 应用包目录权限不足
虽然部署步骤显示成功,但自托管Runner账号可能没有对UWP应用包目录的完全控制权限。
- 解决步骤:
- 定位测试包输出路径:
C:\actions-runner\_work\MY_App\MY_App\repoMY_App\x64\Release\MY_UNITTEST_WIN_UWP - 右键目录>属性>安全>编辑,添加Runner账号并授予完全控制权限
- 勾选“替换所有子对象权限”,应用设置
- 定位测试包输出路径:
4. 调整vstest运行参数
尝试给vstest.console.exe添加参数,强制启用隔离运行模式:
vstest.console.exe YourTestPackage.appx /InIsolation /Platform:x64
/InIsolation:在独立进程中运行测试,避免权限继承问题/Platform:x64:明确指定平台,避免架构不匹配引发的权限异常
内容的提问来源于stack exchange,提问作者Dr.J
相关产品推荐
相关产品推荐

