Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use NuGet packages with an ASP.NET Website on CI Server

I have a number of ASP.NET Web Form Websites (the one with no .csproj file), and I am trying to figure out how to best use NuGet packages with them. When using Visual Studio 2015, adding NuGet packages via the UI works correctly (there is a packages.config in the site root), and the build drops the binaries in the bin folder.

The problem is trying to build the project on TeamCity via MSBuild. For other projects, I can use NuGet.exe with the restore command (either against the csproj or the sln file), and the packages are correctly downloaded and included in the output. However, this doesn't work with the websites, and thus the compile fails due to missing files.

As a last resort, I could write a custom script/build step to manually copy the assemblies to the bin folder, but I'd like to avoid this. Am I missing something? Is there any way to use NuGet with websites outside of Visual Studio?

like image 827
Erick T Avatar asked Sep 27 '15 21:09

Erick T


People also ask

How use NuGet package in asp net?

Open your Visual Studio application. On the Tools menu, select Options. Expand the NuGet Package Manager and select Package Sources. Click the Add button (green plus), and enter the 'Package Name' and 'Package Source URL' of the Syncfusion ASP.NET Web Forms NuGet packages.

How do I add a local NuGet package to Visual Studio?

From Visual Studio's menu, select Tools > Options, and then enter NuGet in the search input. Select the suitable Package Sources, as shown in Figure 1, followed by clicking the green plus button to add your path from set up local feed folder. Provide a name, and then click the OK button.


1 Answers

After some time, I have a workaround that gets me where I need to be, albeit not in the best way.

In newer versions of Visual Studio, when a binary dependency is added to a website via VS, it adds a (binaryfile).dll.refresh file to the bin folder alongside the binary file. The contents of the file is the relative path to the .dll via the packages folder for the solution. In addition, a packages.config file is added to the website.

The way to get it to build on a CI server is:

  1. Ignore (.gitignore, .hgignore) the website's bin folder
  2. Explicitly add the .refresh file(s) in the bin folder
  3. Prior to the actual build, call NuGet restore, passing in the path to the website's packages.config and setting the PackagesDirectory (or SolutionDirectory) to the packages folder for the solution
  4. Pre-Compile, MSBuild will open each refresh file, and copy the file from the location contained in the file.

It's not a great solution, because I now have to call NuGet restore multiple times (once for solution, once for each website), but it does work. I don't know how far back the .refresh file is supported, but it does work in 2015. I may make a change request in NuGet to allow for multiple solutions/packages.configs to be passed in via the command line.

Thanks, Erick

like image 163
Erick T Avatar answered Oct 17 '22 01:10

Erick T