Visual Studio 2017 build agent fails to build with error cs0400
Asked Answered
H

4

10

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).

Heap answered 11/3, 2017 at 16:39 Comment(3)
Since you said "default" queue, can you confirm that means you're using a private agent? Or, are you using the hosted pool? Also, what task is it in the build def? VS Build task? If so, what version is selected in the drop down?Bossuet
Also, are you using VSTS or TFS 2015/2017? RTM/QU1?Bossuet
I'm using a private agent. It's VisualStudio.com online.Heap
A
4

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.

Ambulatory answered 15/3, 2017 at 12:3 Comment(2)
Thanks Chris, I'll try this out and respond back later tonight.Heap
As your response served as a good start point to continue investigation, I'm marking it as the "Answer". But I'll detail my question above, so others can see what actually had happened and how I fixed it.Heap
N
1

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.

Nominalism answered 16/3, 2017 at 19:21 Comment(0)
D
0

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
Deponent answered 15/3, 2017 at 13:46 Comment(1)
Thanks for your response, Nick. But the problem is not in Visual Studio. It builds just fine. It's a Windows Build Agent issue.Heap
M
0

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

Mudslinger answered 17/3, 2017 at 18:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.