Home: CS0006: CSC(0,0): Metadata file 'C:\Windows\system32\config\systemprofile\.nuget\packages\..." could not be found

Created on 13 Oct 2017  路  6Comments  路  Source: NuGet/Home

Details about Problem

Running .NET Core SDK 2.0.2, .NET Framework 4.6.2 and the VS 2017 Build Tools for v 15.4.

Running from within TeamCity I'm intermittently getting build failures like this:

CS0006: CSC(0,0): Metadata file 'C:\Windows\system32\config\systemprofile.nuget\packages...\XX.dll" could not be found

with no indication as to why this is

Detailed repro steps so we can see the same problem

  1. Install dependencies so:

    dotnet-sdk-2.0.2-win-x64.exe /install /quiet /norestart /log "C:\Windows\Temp\dotnet-sdk-2.0.2-win-x64.log""

    vs_buildtools.exe --add Microsoft.VisualStudio.Workload.NetCoreBuildTools --add Microsoft.VisualStudio.Workload.MSBuildTools --add Microsoft.VisualStudio.Workload.WebBuildTools --passive --norestart

  2. Project file looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>net462</TargetFramework>
        <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
      </PropertyGroup>
      <ItemGroup>
        <Compile Include="..\CommonAssemblyInfo.cs">
          <Link>Properties\CommonAssemblyInfo.cs</Link>
        </Compile>
      </ItemGroup>
      <ItemGroup>
        <PackageReference Include="NLog" Version="4.1.2" />
        <PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
      </ItemGroup>
    </Project>
    
  3. Running the following:

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild15.0\Bin\MSBuild.exe ./src/XX.sln /t:Restore;Build /m /nodeReuse:False /tv:15.0 /v:diag /p:RestorePackages="True" /p:Optimize="True" /p:DebugSymbols="True" /p:TreatWarningsAsErrors="True" /p:Configuration="Release" /logger:Fake.MsBuildLogger+TeamCityLogger,"C:\BuildAgent\work\9703509c24d73488\packagesbuild\FAKE.x64\tools\FakeLib.dll" /logger:Fake.MsBuildLogger+ErrorLogger,"C:\BuildAgent\work\9703509c24d73488\packagesbuild\FAKE.x64\tools\FakeLib.dll"

Verbose Logs

Verbose msbuild logs

failed_restore.zip

External

Most helpful comment

I ran into a similar issue using Jenkins. It seems to be related to how the local system account in windows server uses C:\Windows\system32\config\systemprofile as the home directory.

I was able to solve it by setting the NUGET_PACKAGES environment variable to C:\Windows\system32\config\systemprofile\.nuget\packages

https://docs.microsoft.com/en-us/nuget/tools/cli-ref-environment-variables

https://www.techcoil.com/blog/home-directory-of-the-localsystem-account-in-windows-server-2012/

All 6 comments

Try two separate commands:
Msbuild /t:restore
Then
Msbuild /t:build

That might help...

I ran into a similar issue using Jenkins. It seems to be related to how the local system account in windows server uses C:\Windows\system32\config\systemprofile as the home directory.

I was able to solve it by setting the NUGET_PACKAGES environment variable to C:\Windows\system32\config\systemprofile\.nuget\packages

https://docs.microsoft.com/en-us/nuget/tools/cli-ref-environment-variables

https://www.techcoil.com/blog/home-directory-of-the-localsystem-account-in-windows-server-2012/

@pimanac has the correct answer. Set the global packages folder to override the system profile path.

well, I still have the error after setting the env.variable. may be you have other suggestions @pimanac?

I had the same issue and solved it by restoring the nuget packages for the solution prior to creating a new build. Run the command ".nuget\NuGet.exe" restore "yourProject.sln"

This might be an issue of calling the 32-bit version of MSBuild, which causes Windows to do file system redirection to SysWOW64 directory to look for the packages.

Try calling the 64-bit version instead and see if that helps. I also posted about it on StackOverflow: https://stackoverflow.com/a/64984705/1469494

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clairernovotny picture clairernovotny  路  3Comments

blackcity picture blackcity  路  3Comments

rrelyea picture rrelyea  路  3Comments

livarcocc picture livarcocc  路  3Comments

blackchoey picture blackchoey  路  3Comments