从解决方案中的目录引用NuGet软件包 [英] Referencing NuGet packages from directory in solution

查看:89
本文介绍了从解决方案中的目录引用NuGet软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个解决方案,其中包含几个由Visual Studio 2015管理的ASP.NET Core项目.

I have a solution with several ASP.NET Core projects in it, managed in Visual Studio 2015.

我的NuGet软件包当前存储在 C:\ Users \ My User \ .nuget \ packages \ 中.相反,我需要在我的解决方案中有一个Packages目录,并从那里引用软件包.像这样:

My NuGet packages are currently being stored in C:\Users\My User\.nuget\packages\. I need to instead have a Packages directory in my solution and reference packages from there. Like this:

  • 解决方案文件夹
    • src
      • Project1
      • Project2
      • [...]

      我将包从上面的默认路径复制到了解决方案目录,然后删除了项目的所有引用.然后,我将Packages目录添加为NuGet软件包源.最后,我单击管理NuGet程序包"并将其添加到特定项目中,确保选择了我的自定义程序包源.

      I copied the packages from the default path above into a solution directory, then removed all references for a project. I then added my Packages directory as a NuGet Package Source. Finally, I clicked Manage NuGet Packages and added some to a specific project, making sure that my custom package source was selected.

      这似乎可行,但是当我检查引用包的路径时,它仍然是默认的 C:\ Users \ [...] \ packages \ 路径.

      This seemed to work, but when I checked the path of the referenced packages, it was still the default C:\Users\[...]\packages\ path.

      我想念什么?如何从解决方案目录中引用软件包?

      What am I missing? How do I reference the packages from the solution directory?

      我尝试打开.xproj文件,并手动设置路径,就像以前在.csproj文件中所做的那样,但是看来在.xproj文件中是不可能的.或者我只是不知道该怎么做.

      I tried opening up the .xproj file and manually setting the path like I used to sometimes do in .csproj files, but it appears that isn't possible in .xproj files. Or I just don't know how to do it.

      推荐答案

      我将包从上面的默认路径复制到了解决方案目录中……它仍然是默认的C:\ Users [...] \ packages \路径

      I copied the packages from the default path above into a solution directory...it was still the default C:\Users[...]\packages\ path

      您可以混合使用" repositoryPath "和"包源"的概念.

      You may mix up the concept "repositoryPath" and "Packages source".

      尽管您删除了所有引用,将我的Packages目录添加为NuGet软件包源,从自定义软件包源安装了引用,但是您仅更改了Packages源.从自定义软件包源安装软件包后,NuGet将从自定义软件包源下载软件包并将这些下载软件包设置为默认的 repositoryPath ,然后从默认的安装这些软件包.将您的项目的repositoryPath .因此它仍然在默认路径中.

      Although you removed all references, added my Packages directory as a NuGet Package Source, install reference from custom package source, you just only change the Packages source. Once you install the packages from the custom package source, NuGet will download the packages from the custom package source and set those download packages to the default repositoryPath, then install those packages from default repositoryPath to your project. So it was still in the default path.

      如果要更改 .net core 项目的软件包默认位置,则可以设置"NUGET_PACKAGES"环境变量.只需设置"NUGET_PACKAGES" ="c:\ teampackages".或者,您可以在解决方案旁边放置一个NuGet.Config文件,其中包含以下内容:

      If you want to change packages default location for .net core project, you can set "NUGET_PACKAGES" environment variable. Just Set "NUGET_PACKAGES" = "c:\teampackages". Or you can place a NuGet.Config file next to the solution with the following content:

      <?xml version="1.0" encoding="utf-8"?>
        <configuration>
          <config>
            <add key="globalPackagesFolder" value=".\packages" />
          </config>
      </configuration>
      

      有关详细信息,您可以在GitHub上参考同一问题.

      For the detail info, you can refer to the same issue on GitHub.

      但是,我想说的是您可能对结果不满意.因为.Net Core项目依赖于如此多的NuGet软件包.几乎徘徊在1GB左右.我认为您不想为每种解决方案设置所有这些软件包.此外,通过此更改,您需要为每个解决方案在VS中设置其他源..net核心项目非常不便.这就是NuGet团队为.net核心项目设置特殊设置的原因.

      However, what I want to say is that you might not be happy with the results. Because .Net Core projects rely on so many NuGet packages. Almost hovering around 1GB. I think you will not want to set all those packages for each solution. Besides, with this change, you need to set up additional sources in VS for every solution. It`s quite inconvenient for .net core project. This is the reason why NuGet team set the special settings for .net core projects.

      这篇关于从解决方案中的目录引用NuGet软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆