1
votes

I have a Azure DevOps build pipeline that runs as expected on a hosted vs2017 agent, but fails on a self-hosted agent.

The error I get in the Visual Studio build step is:

C:\WINDOWS\TEMP\.NETStandard,Version=v2.0.AssemblyAttributes.cs(4,20): Error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?)

The two agents seems to run the same version of msbuild.

From the diagnostic output from msbuild I can see that the output from the ResolvePackageDependencies task contains a lot of packages where the ResolvedPath is empty, for instance:

runtime.native.System/4.3.0
              Name=runtime.native.System
              Path=runtime.native.system/4.3.0
              ResolvedPath=
              Type=package
              Version=4.3.0

But the NuGet restore step seems to complete without problems.

Any suggestions for what I am missing?

2

2 Answers

0
votes

I believe I had a similar issue. I ended up having to install the latest Nuget and then run Nuget on the solution including a NuGet.config file.

  1. Add a nuget.config to your solution so it is part of your repo/pull. Mine is in the same directory as the solution file. Example below
  2. Add a task "NuGet Tool Installer" - I install NuGet 4.4.1, just put 4.4.1 in the Version to install input.
  3. Add a task "NuGet Installer" - Different from above. Version 0.* - I have not tried the other versions.
    1. Set the Path to the solution. IE. $(Build.Repository.LocalPath)/Source/Sample.sln
    2. Add the path to the Nuget config file. Example $(Build.Repository.LocalPath)/Source/nuget.config

Nuget.config contains how to get the packages. Add other locations if you get packages from other sources like a local folder or something.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
    Used to specify the default Sources for list, install and update.
    See: nuget.exe help list
    See: nuget.exe help install
    See: nuget.exe help update
-->
<packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<packageRestore>
  <!-- Allow NuGet to download missing packages -->
  <add key="enabled" value="True" />

  <!-- Automatically check for missing packages during build in Visual Studio -->
  <add key="automatic" value="True" />
</packageRestore>

Your build task should run fine now and find all the packages.

0
votes

Self-hosted Azure Devops build cant resolve packages

According to the error message, it seem nuget not restore the reference from SDK.

To resolve this issue, we need update our nuget.exe version to 4.0 and above.

In the NuGet tool installer we could specify the nuget.exe version:

enter image description here

As you comment above, it seems you have already use nuget installer, in this case, you can try to update Visual Studio to 15.3 and above on the build server. Because VS only adds proper support for .NET Core 2.0 SDK in version 15.3.

Finally, if your project/solution is .net core/standard you can use dotnet restore and then run dotnet build to compile your app.

Hope this helps.