Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Powershell or Command Prompt as administrator during Visual Studio Team Services build

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?

like image 275
Edward Rixon Avatar asked Apr 11 '16 13:04

Edward Rixon


People also ask

How do I run PowerShell as administrator in Visual Studio?

On the Windows desktop, right-click the Visual Studio shortcut, and then select Properties. Select the Advanced button, and then select the Run as administrator check box. Select OK, and then select OK again.

How do I run a PowerShell script as administrator from command line?

Step 1: Open the Command Prompt, and type the PowerShell as a command, then press Enter key. Step 2: Now, the command prompt will turn to Windows PowerShell. Step 3: Type the command start-process PowerShell -verb runas and press "enter" key. Step 4: It will bring up an elevated Windows PowerShell as an administrator.


1 Answers

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

like image 117
Eddie Chen - MSFT Avatar answered Oct 01 '22 12:10

Eddie Chen - MSFT