0
votes

on this msdn site I have found guide how to build and deploy asp.net5 app to Azure with Visual Studio Team Services. 1st step is to install dnx with following powershell prebuild script

    # bootstrap DNVM into this session.
&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}

# load up the global.json so we can find the DNX version
$globalJson = Get-Content -Path $PSScriptRoot\global.json -Raw -ErrorAction Ignore | ConvertFrom-Json -ErrorAction Ignore

if($globalJson)
{
    $dnxVersion = $globalJson.sdk.version
}
else
{
    Write-Warning "Unable to locate global.json to determine using 'latest'"
    $dnxVersion = "latest"
}

# install DNX
# only installs the default (x86, clr) runtime of the framework.
# If you need additional architectures or runtimes you should add additional calls
# ex: & $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -r coreclr
& $env:USERPROFILE\.dnx\bin\dnvm install $dnxVersion -Persistent

 # run DNU restore on all project.json files in the src folder including 2>1 to redirect stderr to stdout for badly behaved tools
Get-ChildItem -Path $PSScriptRoot\src -Filter project.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }

This script works when I am using hosted agent, however when I want to use self hosted agent I am getting following error:

out-file : Access to the path 'C:\1' is denied.
At C:\Users\xy\Desktop\agent\_work\1\s\Prebuild.ps1:28 char:88
+ ... ject.json -Recurse | ForEach-Object { & dnu restore $_.FullName 2>1 }

My self hosted agent work location is C:\Users\xy\Desktop\agent_work . I do not see that much into a powershell, so I would like to ask you, for help. Thank you.

1

1 Answers

1
votes

This is because your self build agent is running as a service with "Network Service" account by default.

To fix this issue, you can either change it to run with an account with administrator permission by command:

C:\Users\xy\Desktop\agent\Agent\VsoAgent.exe /ChangeWindowsServiceAccount

Or configure your build agent to run interactively and then run it as administrator.

Refer to this link for details:Run the agent