Dodzi Dzakuma
Dodzi Dzakuma

Reputation: 1426

Methods for ensuring Visual Studio Solution NuGet packages are reinstalled during TeamCity CI build

I am having an issue where NuGet packages are not being reinstalled during a CI build on TeamCity despite using a NuGet Installer build step for my build project.

I have narrowed the problem down to a specific issue. On my development machine the Path to the reference is clearly defined.

Developer Machine

On the build machine, the Path to the reference is blank.

Build Machine

I checked the build machine to make sure that NuGet is properly downloading new version of the packages. It is. I also checked to make sure that the solution will build if I specify a path. It does. However, every time a build goes through CI it fails because the reference path for certain packages do not get restored properly.

The packages I use for my solution are checked into version control and available in the packages folder of my solution (for good measure).

I have attempted to change how TeamCity tells NuGet to update packages by specifying to use the packages.config file instead of the sln file.

I have seen some possible solutions, but they require manually updating the packages through the GUI or the information is no longer relevant.

Reference:

Nuget Packages are missing in Visual Studio

Nuget not updating project references

MSBuild cannot find a reference

Teamcity failing to install packages via nuget

Question

How to a fix the problem with NuGet package resolution in this situation (no direct human intervention on the build machine[s])?

Visual Studio Solution HintPath Settings

<Reference Include="Company.EnterpriseD.Api, Version=5.0.2.34289, Culture=neutral, processorArchitecture=MSIL">
  <HintPath>..\packages\Company.EnterpriseD.Api.5.0.2\lib\net462\Company.EnterpriseD.Api.dll</HintPath>
</Reference>
<Reference Include="Company.EnterpriseD.Database, Version=5.0.2.29628, Culture=neutral, processorArchitecture=AMD64">
  <HintPath>..\packages\Company.EnterpriseD.Database.5.0.2\lib\net462\Company.EnterpriseD.Database.dll</HintPath>
</Reference>

Error Log From TeamCity Visual Studio Solution Build

[06:46:42]Step 2/3: Visual Studio (sln) (7s)
[06:46:42][Step 2/3] Starting: C:\BuildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MsBuildBootstrap.exe /workdir:C:\BuildAgent\work\777f4dbff737cc31 "/msbuildPath:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\MSBuild.exe"
[06:46:42][Step 2/3] in directory: C:\BuildAgent\work\777f4dbff737cc31
[06:46:45][Step 2/3] Company.EnterpriseD.EmailRelay.sln.teamcity: Build target: TeamCity_Generated_Build (4s)
[06:46:45][Company.EnterpriseD.EmailRelay.sln.teamcity] TeamCity_Generated_Build (4s)
[06:46:45][TeamCity_Generated_Build] MSBuild (4s)
[06:46:45][MSBuild] Company.EnterpriseD.EmailRelay.sln: Build target: Build (3s)
[06:46:45][Company.EnterpriseD.EmailRelay.sln] ValidateSolutionConfiguration
[06:46:45][Company.EnterpriseD.EmailRelay.sln] Build (3s)
[06:46:45][Build] MSBuild (3s)
[06:46:45][MSBuild] Company.EnterpriseD.EmailRelay.Relaying\Company.EnterpriseD.EmailRelay.Relaying.csproj: Build default targets (3s)
[06:46:46][Company.EnterpriseD.EmailRelay.Relaying\Company.EnterpriseD.EmailRelay.Relaying.csproj] PrepareForBuild
[06:46:46][Company.EnterpriseD.EmailRelay.Relaying\Company.EnterpriseD.EmailRelay.Relaying.csproj] _GetProjectReferenceTargetFrameworkProperties
[06:46:46][Company.EnterpriseD.EmailRelay.Relaying\Company.EnterpriseD.EmailRelay.Relaying.csproj] ResolveProjectReferences (3s)
[06:46:46][ResolveProjectReferences] MSBuild (3s)
[06:46:46][MSBuild] Company.EnterpriseD.EmailRelay.Database\Company.EnterpriseD.EmailRelay.Database.csproj: Build default targets (3s)
[06:46:46][Company.EnterpriseD.EmailRelay.Database\Company.EnterpriseD.EmailRelay.Database.csproj] PrepareForBuild
[06:46:46][Company.EnterpriseD.EmailRelay.Database\Company.EnterpriseD.EmailRelay.Database.csproj] ResolveAssemblyReferences
[06:46:47][Company.EnterpriseD.EmailRelay.Database\Company.EnterpriseD.EmailRelay.Database.csproj] CoreResGen
[06:46:47][Company.EnterpriseD.EmailRelay.Database\Company.EnterpriseD.EmailRelay.Database.csproj] CoreCompile (1s)
[06:46:47][CoreCompile] Csc (1s)
[06:46:47][Csc] C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:x64 /errorreport:prompt /define:TRACE /highentropyva+ /reference:C:\BuildAgent\work\777f4dbff737cc31\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll /reference:C:\BuildAgent\work\777f4dbff737cc31\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\mscorlib.dll" /reference:C:\BuildAgent\work\777f4dbff737cc31\packages\NLog.5.0.0-beta07\lib\net45\NLog.dll /reference:C:\BuildAgent\work\777f4dbff737cc31\packages\Oracle.ManagedDataAccess.12.1.24160719\lib\net40\Oracle.ManagedDataAccess.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.ComponentModel.DataAnnotations.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.Configuration.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.Data.dll" /reference:C:\BuildAgent\work\777f4dbff737cc31\packages\System.Data.SQLite.Core.1.0.105.0\lib\net46\System.Data.SQLite.dll /reference:C:\BuildAgent\work\777f4dbff737cc31\packages\System.Data.SQLite.EF6.1.0.105.0\lib\net46\System.Data.SQLite.EF6.dll /reference:C:\BuildAgent\work\777f4dbff737cc31\packages\System.Data.SQLite.Linq.1.0.105.0\lib\net46\System.Data.SQLite.Linq.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.IO.Compression.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.Net.Http.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.Runtime.Serialization.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.ServiceModel.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.Transactions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\System.Xml.Linq.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\x64\Release\Company.EnterpriseD.EmailRelay.Database.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset" /subsystemversion:6.00 /resource:obj\x64\Release\Company.EnterpriseD.EmailRelay.Database.Properties.Resources.resources /resource:database_defintion.sql,Company.EnterpriseD.EmailRelay.Database.database_defintion.sql /target:library /utf8output EmailDatabase.cs Mono.Options-PCL.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs "C:\BuildAgent\temp\buildTmp\.NETFramework,Version=v4.6.2.AssemblyAttributes.cs"
[06:46:47][Csc] Using shared compilation with compiler from directory: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\Roslyn
[06:46:49][Csc] EmailDatabase.cs(5, 23): error CS0234: The type or namespace name 'Database' does not exist in the namespace 'Company.EnterpriseD' (are you missing an assembly reference?)
[06:46:49][Step 2/3] Error message is logged
[06:46:49][Csc] EmailDatabase.cs(6, 23): error CS0234: The type or namespace name 'Api' does not exist in the namespace 'Company.EnterpriseD' (are you missing an assembly reference?)
[06:46:49][MSBuild] Company.EnterpriseD.EmailRelay.Database\Company.EnterpriseD.EmailRelay.Database.csproj: Build default targets
[06:46:49][Company.EnterpriseD.EmailRelay.Database\Company.EnterpriseD.EmailRelay.Database.csproj] Project Company.EnterpriseD.EmailRelay.Database\Company.EnterpriseD.EmailRelay.Database.csproj failed.
[06:46:49][MSBuild] Company.EnterpriseD.EmailRelay.Queuing\Company.EnterpriseD.EmailRelay.Queuing.csproj: Build default targets
[06:46:49][Company.EnterpriseD.EmailRelay.Queuing\Company.EnterpriseD.EmailRelay.Queuing.csproj] PrepareForBuild
[06:46:49][Company.EnterpriseD.EmailRelay.Queuing\Company.EnterpriseD.EmailRelay.Queuing.csproj] _GetProjectReferenceTargetFrameworkProperties
[06:46:49][Company.EnterpriseD.EmailRelay.Queuing\Company.EnterpriseD.EmailRelay.Queuing.csproj] ResolveProjectReferences
[06:46:49][ResolveProjectReferences] MSBuild
[06:46:49][MSBuild] Company.EnterpriseD.EmailRelay.Database\Company.EnterpriseD.EmailRelay.Database.csproj: Build default targets
[06:46:49][Company.EnterpriseD.EmailRelay.Database\Company.EnterpriseD.EmailRelay.Database.csproj] Project Company.EnterpriseD.EmailRelay.Database\Company.EnterpriseD.EmailRelay.Database.csproj failed.
[06:46:49][Step 2/3] Process exited with code 1
[06:46:49][Step 2/3] MSBuild output
[06:46:49][Step 2/3] Process exited with code 1
[06:46:50][Step 2/3] Step Visual Studio (sln) failed

Upvotes: 2

Views: 347

Answers (1)

Dodzi Dzakuma
Dodzi Dzakuma

Reputation: 1426

I found a solution to the problem.

The Specific Version flag was set to True for the reference. This means that the program was trying to resolve down to the Major.Minor.Patch.Build version of the assemblies being referenced.

Please see the picture below.

enter image description here

In this case the CI agent is looking for the specific version 5.0.2.34289. However, The assembly version available on our internal NuGet server is 5.0.2.35182. The API of the assembly hasn't changed, only the build version. Each time our CI runs, it rebuilds the assemblies for use. The reason this happens is to ensure that the tests for our assemblies run and pass before building projects that are dependent on them.

When the CI server when to resolve the path it was looking for the specific version see picture below.

enter image description here

When it couldn't resolve it down to the build version, it would give up and say that no compatible versions of the assemblies exist. This is why it would fail on the build machine.

This issue was exacerbated by the fact that I set the project to clean the checkout folder on builds (I would not have found out about the issue otherwise. I always clean before checking out!).

Much thanks to @OscarE.FraxedasTormo for stepping me through all of the other possibilities it could have been.

Upvotes: 1

Related Questions