Artak
Artak

Reputation: 2887

Visual Studio 2017 build agent fails to build with error cs0400

I've installed the VS 2017 Build agent and registered it in the 'Default' agent queue. The project I'm trying to build is a VS 2017 class library project, targeting .Net Standard 1.0. When building from Visual Studio, build succeeds. However the build on the build agent fails.

T16:05:59.0389362Z ##[error]C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp.NETStandard,Version=v1.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?)

By comparing the build logs with my local build I can see that the build agent calls the csc.exe with missing 'reference' attributes. My project has no any explicit references - it just requires .NetStandard 1.0 libraries (SDK). The command line the build agent uses is:

\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702,1705 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE;RELEASE;NETSTANDARD1_0 /debug- /debug:portable /filealign:512 /nologo /optimize+ /out:obj\Release\netstandard1.0\Geo.Common.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Team Tools\Static Analysis Tools\Rule Sets\MinimumRecommendedRules.ruleset" /target:library /warnaserror- /utf8output /deterministic+ Distance.cs DistanceExtensions.cs GeoCoordinate.cs Unit.cs "C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp.NETStandard,Version=v1.0.AssemblyAttributes.cs" obj\Release\netstandard1.0\Geo.Common.AssemblyInfo.cs

I know I can just hardcode the 'reference' list as command line attributes to the build step in build definition, but that's a workaround. What is the right way to fix this ?

Thanks!

UPDATE Turned out that the reason for the failure was that the earlier step in the build definition, the NuGet Restore was using the 3.5 version of nuget.exe. Because the project file was in VS 2017 format, nuget.exe was unable to find any referenced packages, so was completing successfully without actually pulling anything in. Thus, on the next step, the build was failing as no NuGet packages (hence any assemblies) were found.

SOLUTION

I downloaded nuget.exe 4.0 (found here) and place it in the agent's work directory (D:\VsAgentWork\nuget.exe in my case). Then, I customized the NuGet Restore step, to reference the nuget.exe from the provided location (....\nuget.exe).

Upvotes: 10

Views: 6702

Answers (4)

Vijay Machiraju
Vijay Machiraju

Reputation: 176

If you want to use the hosted VS2017 agent pool for your .net core app, you can run 'dotnet restore', and that should work too: https://www.visualstudio.com/en-us/docs/build/apps/aspnet/ci/build-aspnet-core

Upvotes: 0

Matt
Matt

Reputation: 13349

Had this exact same issue, and switching from

nuget restore xyz.sln

to

dotnet restore
nuget restore xyz.sln

before the build itself fixed it.

Upvotes: 1

Nick Lucas
Nick Lucas

Reputation: 39

I experienced this with VS2017 too, it seems to be a bug.

In the first instance just restart VS, but I did find the full steps are sometimes needed to resolve the issue:

  1. Close VS
  2. Delete the .vs/ folder
  3. Delete any bin/ and obj/ folders
  4. Reload VS and run a rebuild

Upvotes: 0

Chris Patterson
Chris Patterson

Reputation: 665

You need to restore you package for your solution. For .NET Core you need to either do this with the dotnet cli or with the MSBuild /t:restore target or you can download NuGet 4 from the nuget site and put that on your build machine and specify it in the path on the NuGet installer task.

Upvotes: 4

Related Questions