Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 882
Artak Avatar asked Mar 11 '17 16:03

Artak


2 Answers

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.

like image 93
Chris Patterson Avatar answered Oct 21 '22 04:10

Chris Patterson


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.

like image 1
Matt Avatar answered Oct 21 '22 06:10

Matt