Search code examples
nugetcloudteamcity

how to installing nuget packages teamcity cloud?


I am new to CI/CD and want to set up our .net project on the TeamCity cloud. when I am adding build steps how can I install NuGet? on cloud version, there isn't any option to install it?


Solution

  • Assuming you want to restore packages, NuGet is built into the dotnet cli and MSBuild. I assume by "install NuGet" you mean aquire nuget.exe. For the most common scenarios (restore, configure sources that are different on CI vs dev boxes, MSBuild pack), nuget.exe is unnecessary.

    If all the projects in your solution/repo are SDK style (for example .NET Core, .NET Standard, or .NET 5 or higher. But there's a misconception that .NET Framework projects can't be SDK style; they can). You can use this:

    dotnet restore
    

    If your projects are not SDK style (created using Visual Studio's ".NET Framework" version of project templates), and you use PackageReference for your NuGet references, you can use this:

    msbuild -t:restore
    

    If your projects use packages.config, then from MSBuild/Visual Studio 16.3 and higher, you can use this:

    msbuild -t:restore -p:RestorePackagesConfig=true
    

    This way, not only do you not need nuget.exe, but you're also protected from using a version of nuget.exe that isn't fully compatible with the version of dotnet/msbuild that you're using. This has rarely happened, and to my knowledge nuget.exe has never broken backwards compatibility. But since .NET 5 introduced the net5.0-windows target framework, some changes to the intermediate files that NuGet writes were made, and customers, even if they were not using net5.0-windows, had their builds break if they restored with an old version of nuget.exe, but then tried to build with a new version of msbuild. By using msbuild or dotnet to do both the restore and build, you know the versions are always in-sync.

    If you really need nuget.exe, the Installing NuGet client tools documentation has a URL where you can download it, and there's also a json file with all versions of nuget.exe listed that you can use in a script. But remember you can be creative, like if you host your own CI agents, you can pre-install nuget.exe on the machine image, or have your own "CDN" on the same network as the agents, so it's always downloading from a local network. Your own creativity (and ability to work with your IT department) is your limit!