NuGet restore fails with error MSB1009: Project file does not exist when running Bamboo agent service as LOCAL SYSTEM
Problem
NuGet restore during a MSBuild Task fails with error MSB1009: Project file does not exist when running Bamboo agent service as the LOCAL SYSTEM
account. The following appears in the build log:
build 13-Jan-2020 15:07:00 MSBUILD : error MSB1009: Project file does not exist. [C:\Bamboo\bamboo-agent-home\xml-data\build-dir\PROJ-PLAN-JOB1\BUILD_msbuild.proj]
build 13-Jan-2020 15:07:00 Switch: C:\windows\system32\config\systemprofile\AppData\Local\Temp\NuGetScratch\dtuk4fmu.hcu.nugetinputs.targets
Diagnosis
Environment
Bamboo agent running as a Windows Service under the
LOCAL SYSTEM
account.
Cause
NuGet is unable to write to C:\windows\system32\config\systemprofile\AppData\Local\Temp
while running under this context
Workaround
Option 1: Override the TMP and TEMP directory environment variables values to a different location
Configure the MSBuild task at Plan Configuration >> Tasks >> MSBuild and set the Environment Variables field to override the values. Example:
TMP="C:\Bamboo\bamboo-agent-home\temp" TEMP="C:\Bamboo\bamboo-agent-home\temp"
Option 2: Configure the Bamboo agent Windows Service to run under a local user account context
- Start >> Run >> services.msc
- Find the Atlassian Bamboo remote agent service
- Right click >> Properties >> Log On
- Configure the service to run as a local user account of your choosing
- Ensure this local user account as full ownership over the
$BAMBOO_AGENT_HOME
directory - Restart the agent