Team city build with NuGet packages

2019-07-29 11:13发布

问题:

I have set up a build in team city, with a NuGet package reference in the test project.

The folder structre I have used is

\
|- Project1
  \- Project1.csproj
|-  Project1.Test
 \- Project1.Test.csproj
|- packages
 \- lib
  \- RhinoMocks

The Project1 project builds sucessfully, but the Test project fails on the ResolveAssemblyReferences step. The relative path seems to be incorrect.

[13:16:55]: [ResolveAssemblyReference] C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360, 9): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Rhino.Mocks, Version=3.6.0.0, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
[13:16:55]: [ResolveAssemblyReference]         For SearchPath "{HintPathFromItem}".
[13:16:55]: [ResolveAssemblyReference]         Considered "..\packages\RhinoMocks.3.6\lib\Rhino.Mocks.dll", but it didn't exist.

TeamCity build config:

  • MSBuild task
  • Build file path: Project1.Test\Project.Test.csproj
  • Working directory: %system.teamcity.build.checkoutDir%\Project1.Test
  • VCS root points to the root of the folder structure above.

As far I can tell this may be a MSBuild issue, I get the same error when I run MSBuild at the command line in the checkout folder on the build agent.

More info: The hint path is being provided by the Nuget package configuration. Within Visual Studio the package reference works correctly. However, when running via MSBuild, it seems confused about its current directory. The ..\packages... path is actually the verbatim reference path from Nuget.

回答1:

I'm confused about this part of your project structure:

|- packages
 \- lib
  \- RhinoMocks

This shouldn't be necessary if you're pulling the packages in from NuGet. The only file under "packages" that should be checked into source control is repositories.config.

Also, when TeamCity runs MSBuild, how are you downloading the relevant NuGet dependencies? Is it via the TeamCity "NuGet Installer" or have you configured your Solution/Projects to auto run nuget install?



回答2:

You've got a mixed reference, with a strong assembly name (the Version etc.) and a hint path. If the assembly is in the GAC on your machine, it will be located even if the hint path is wrong. If it isn't in the GAC on the build machine, it can't be found. Check in your project file and see if the HintPath metadata on the Reference is the correct path (looks like it should be "..\packages\lib\RhinoMocks..." instead of what appears in the output.

That's a bunch of ifs, for any more ideas I'd need to see what's inside the project file that is failing.