Later this day I switched over to another task. TeamCity provides a fully functional NuGet repository server. My plan was migrating our own libraries and some 3rd party libraries from a direct dependency (binary file or as Git submodule) inside the project Git repositores to a system like Maven or Ivy or … well … NuGet for .NET.

First I set up a new Git repository containing all our 3rd party dependencies which are not available in the public NuGet repositories. The Git repository had the following structure

/.nuget
  /NuGet.config
  /NuGet.exe
  /NuGet.targets
/External.Lib.1
  External.Lib.1.nuspec
  /lib
    External.Lib.1.dl
/External.Lib.2
  External.Lib.2.nuspec
  /lib
    External.Lib.2.dl

The .nuget directory came from Visual Studio. I used the NuGet.exe binary for local testing.

In TeamCity I created a new Build Configuration and chose **/*.nupkg as Artifact Path.

The rest of the Build Step configuration can be seen on the attached image.

After running the first build I realized that the .nupkg had the wrong directory structure. The structure External.Lib.1.nupkg for example was

/External.Lib.1
  External.Lib.1.nuspec
  /lib
    External.Lib.1.dl

This is not the expected directory tree.

Reason for that is, that TeamCity automatically appends the parameter -BasePath to the NuGet.exe statement resulting in (taken from build log)

NuGet command: <tc>\buildAgent\tools\NuGet.CommandLine.2.0.40001.nupkg\tools\NuGet.exe pack <tc>\buildAgent\work\80f29a1b916940aa\External.Lib.1\External.Lib.1.nuspec -OutputDirectory <tc>\buildAgent\work\80f29a1b916940aa\dist -BasePath <tc>\buildAgent\work\80f29a1b916940aa -Verbose -Version 0.7 -Properties Configuration=Release

There is no frontend option to disable the setting of BasePath parameter. The configuration parameter Additional commandline arguments did not work as expected as it quotes the entire string.

Thanks to the  parameter Build Path > Properties we can do a little bit of quoting magic and overwrite the BasePath option

Configuration=Release " -BasePath "

Yes, there are two quotes as the usage of Properties puts the NuGet command itself in quotation marks.

The complete command resolves to

... -BasePath <tc>\buildAgent\work\80f29a1b916940aa -Verbose -Version 0.15 -Properties "Configuration=Release " -BasePath ""
and everything is fine 😉

I am asking you for a donation.

You liked the content or this article has helped and reduced the amount of time you have struggled with this issue? Please donate a few bucks so I can keep going with solving challenges.


0 Comments

Leave a Reply