本文介绍了将nuget软件包存储在构建服务器上的备用位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本地进行开发时,我将Nuget软件包安装在默认位置(解决方案文件夹中的\ packages).

When developing locally I have my Nuget packages installed in the default location (\packages within solution folder).

我想在构建服务器上有一个其他文件夹,该文件夹也可以用作我可以下载软件包的存储库路径,从而有效地为我提供了软件包的本地缓存,该缓存将在整个构建中持续存在,而不需要每次都重新下载所有软件包构建.

I want have a different folder on my build server that acts as the repository path where I can download packages too, effectively giving me a local cache of packages which will persist across builds, not requiring all packages to be downloaded fresh every time build.

在CI服务器上,我将nuget.config文件拖放到解决方案目录中,该文件指定新包文件夹的位置:

On the CI server I drop a nuget.config file into the solution directory which specifies the location of the new packages folder:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <!-- Specify repository path -->
    <add key="repositorypath" value="x:\nugetPackages" />
  </config>
  <activePackageSource>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
  </activePackageSource>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
</configuration>

这部分工作正常,并将软件包下载到x:\ nugetPackages \,但是当我尝试构建解决方案时,由于找不到dll而出现异常.这是有道理的,因为引用的hintPath是".. \ packages \ lib \ lib.dll",而我希望它完全位于其他驱动器上.

This part works fine and downloads packages to x:\nugetPackages\ but when I try to build the solution I get exceptions as the dlls are not found. This makes sense as the hintPath for the references is "..\packages\lib\lib.dll" whereas I want it to be on a different drive completely.

我的主要msbuild任务只是构建解决方案文件.为了使其正常工作,我在msbuild脚本中尝试了以下各种选项:

My main msbuild task is just building the Solution file. To get this to work I've tried various options in my msbuild script, from:

以上所有内容都会导致许多警告,类似于:error CS0246: The type or namespace name 'HttpRequestMessage' could not be found (are you missing a using directive or an assembly reference?)

All of the above result in lots of warnings similar to: error CS0246: The type or namespace name 'HttpRequestMessage' could not be found (are you missing a using directive or an assembly reference?)

我设法通过将MSBuild脚本更改为:

I've managed to get it to work by altering the MSBuild script to:

  1. 将nuget软件包恢复到缓存"文件夹(例如x:\ nugetPackages).
  2. 将这些软件包复制到默认位置(.. \ packages).
  3. 构建解决方案.

这似乎是解决问题的漫长方法,我是否遗漏了一些明显的东西?我读过一些博客文章,人们在其中使用XSLT重写解决方案中所有项目文件的'hintPath'元素-肯定有更好的方法吗?

This seems to be an overly long winded way of dealing with this, am I missing something obvious? I've read a few blog posts where people are using XSLT to rewrite the 'hintPath' element for all project files in the solution - surely there's a better way of doing this?

推荐答案

NuGet在%localappdata%\NuGet\Cache处具有内置的本地缓存,您可以将其用作nuget.config中的程序包源.

NuGet has a built-in local cache at %localappdata%\NuGet\Cache which you could use as a package source in your nuget.config.

NuGet将按照配置中定义的顺序从packagesources中恢复软件包,并在其首次命中时停止扫描. (activepackagesource应该是汇总的全部" Feed)

NuGet will restore packages from packagesources in the order defined in your config and stop scanning at its first hit. (activepackagesource should be the aggregate 'All' feed)

这篇关于将nuget软件包存储在构建服务器上的备用位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:13