在Visual Studio Team Services构建期间以管理员身份运行Powershell或命令提示符 [英] Run Powershell or Command Prompt as administrator during Visual Studio Team Services build

查看:218
本文介绍了在Visual Studio Team Services构建期间以管理员身份运行Powershell或命令提示符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目上,我们将延迟对程序集进行签名。在构建过程中,我需要多次使用强名称工具,以关闭强名称验证,然后在打包程序集之前对其进行完全签名。我尝试使用Powershell步骤关闭验证,但此错误返回:



脚本:

  $ testprojs = gci Project。*。dll -r 
$ testprojs | %{
sn -Vr $ _
写输出$(关闭 + $ _。Name的sn验证)
}

错误:

 无法打开注册表项-使用
所选选项需要管理员权限。使用管理员命令提示符来完成这些任务。

所以我创建了一个运行第一个脚本的脚本,但是添加了-elevated参数。



我还尝试使用命令提示符步骤代替powershell。这也返回了相同的错误。

 在( Project。*。dll)中为/ r%g做sn -Vr %g 

当我尝试对构建代理机器本身运行rdp相同的脚本时,它可以工作如预期。



有任何想法吗?

解决方案

根据您的描述:


当我尝试运行该脚本rdp到构建代理时机器
本身,它可以按预期工作。


我假设您正在使用自己的构建代理进行构建。然后,这可能是由于构建代理未使用管理员帐户运行引起的。请更新您的构建代理以使用管理员帐户运行,然后重试。


运行代理以服务运行



如果将代理部署为Windows服务运行,则可以从服务管理单元控制代理
的运行状态。运行
services.msc并查找 VSO代理()。如果您
需要更改登录帐户,请不要通过
服务管理单元执行此操作。而是在提升的命令提示符下运行:
C:\Agent\Agent\VsoAgent.exe / ChangeWindowsServiceAccount交互式运行


否则,如果您安装了可交互运行的代理,则可以通过启动Agent\VsoAgent.exe来启动代理


有关详细信息,请参见此链接:运行代理


I am working on a project where we are delay signing the assemblies. I need to use the strong name tool a couple times during the build, to turn off strong name verification, and then to fully sign the assemblies before they are packaged. I attempted to use a powershell step to turn off verification, but it came back with this error:

Script:

$testprojs = gci Project.*.dll -r
$testprojs | % {
            sn -Vr $_
            write-output $("Turned off sn verification for " + $_.Name)
}

Error:

Failed to open registry key -- Administrator permissions are needed to use
the selected options. Use an administrator command prompt to complete these tasks.

So I created a script that would run the first one, but added the -elevated parameter. This made no difference.

I also tried using a command prompt step instead of powershell. This also returned the same error.

For /r %g in ("Project.*.dll") DO sn -Vr %g

When I tried running this same script rdp'd to the build agent machine itself, it works as intended. It's only when it runs as a step in the build does it not work.

Any ideas?

解决方案

According to your description:

When I tried running this same script rdp'd to the build agent machine itself, it works as intended.

I assume you are using your own build agent for build. Then this may caused by the build agent isn't running with an administrator account. Please update your build agent to run with administrator account and then try again.

Run the agent Run as a service

If you deployed the agent to run as a Windows service, then the agent running status can be controlled from the Services snap-in. Run services.msc and look for "VSO Agent ()". If you need to change the logon account, don't do it from the services snap-in. Instead, From an elevated Command Prompt, run: C:\Agent\Agent\VsoAgent.exe /ChangeWindowsServiceAccount Run interactively

Otherwise if you installed the agent to run interactively, the agent can be started by launching Agent\VsoAgent.exe.

Refer to this link for details: Run the agent

这篇关于在Visual Studio Team Services构建期间以管理员身份运行Powershell或命令提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆