简体   繁体   English

从解决方案中的目录引用NuGet软件包

[英]Referencing NuGet packages from directory in solution

I have a solution with several ASP.NET Core projects in it, managed in Visual Studio 2015. 我有一个解决方案,其中包含几个由Visual Studio 2015管理的ASP.NET Core项目。

My NuGet packages are currently being stored in C:\\Users\\My User\\.nuget\\packages\\ . 我的NuGet软件包当前存储在C:\\Users\\My User\\.nuget\\packages\\ I need to instead have a Packages directory in my solution and reference packages from there. 相反,我需要在我的解决方案中有一个Packages目录,并从那里引用软件包。 Like this: 像这样:

  • SolutionFolder 解决方案文件夹
    • src SRC
      • Project1 项目1
      • Project2 项目2
      • [...] [...]
    • Packages

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. 然后,我将Packages目录添加为NuGet软件包源。 Finally, I clicked Manage NuGet Packages and added some to a specific project, making sure that my custom package source was selected. 最后,我单击“管理NuGet程序包”并将其添加到特定项目中,确保选择了我的自定义程序包源。

This seemed to work, but when I checked the path of the referenced packages, it was still the default C:\\Users\\[...]\\packages\\ path. 这似乎可行,但是当我检查引用包的路径时,它仍然是默认的C:\\Users\\[...]\\packages\\路径。

What am I missing? 我想念什么? How do I reference the packages from the solution directory? 如何从解决方案目录引用软件包?

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. 我尝试打开.xproj文件并手动设置路径,就像以前在.csproj文件中所做的那样,但是似乎在.xproj文件中是不可能的。 Or I just don't know how to do it. 或者我只是不知道该怎么做。

I copied the packages from the default path above into a solution directory...it was still the default C:\\Users[...]\\packages\\ path 我将包从上面的默认路径复制到了解决方案目录中……它仍然是默认的C:\\ Users [...] \\ packages \\路径

You may mix up the concept " repositoryPath " and " Packages source ". 您可以混合使用“ repositoryPath ”和“ Packages source ”的概念。

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. 尽管您删除了所有引用,将我的Packages目录添加为NuGet软件包源,从自定义软件包源安装了引用,但是您仅更改了Packages源。 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 . 从自定义软件包源安装软件包后,NuGet将从自定义软件包源下载软件包,并将这些下载软件包设置为默认的repositoryPath ,然后将这些软件包从默认的repositoryPath安装到您的项目中 So it was still in the default path. 因此它仍然在默认路径中。

If you want to change packages default location for .net core project, you can set "NUGET_PACKAGES" environment variable. 如果要更改.net核心项目的软件包默认位置,则可以设置“ NUGET_PACKAGES”环境变量。 Just Set "NUGET_PACKAGES" = "c:\\teampackages". 只需设置“ NUGET_PACKAGES” =“ c:\\ teampackages”。 Or you can place a NuGet.Config file next to the solution with the following content: 或者,您可以在解决方案旁边放置一个NuGet.Config文件,其中包含以下内容:

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

For the detail info, you can refer to the same issue on GitHub. 有关详细信息,您可以在GitHub上参考相同的问题

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. 因为.Net Core项目依赖许多NuGet软件包。 Almost hovering around 1GB. 几乎徘徊在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. 此外,通过此更改,您需要为每个解决方案在VS中设置其他源。 It`s quite inconvenient for .net core project. .net核心项目非常不便。 This is the reason why NuGet team set the special settings for .net core projects. 这就是NuGet团队为.net核心项目设置特殊设置的原因。

You can create a Nuget.config in your src directory and set the repositoryPath 您可以在src目录中创建一个Nuget.config并设置repositoryPath

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

</configuration>

You can create a local nuget repository for offline development and instead of having a packages directory use local repo. 您可以创建用于脱机开发的本地nuget存储库,而不是使用本地存储库来打包目录。 here is guide: 这是指南:

CREATING A LOCAL NUGET REPOSITORY FOR OFFLINE DEVELOPMENT 创建本地Nuget存储库以进行离线开发

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio 解决方案资源管理器不断显示我不再引用的 nuget 个包 - Visual Studio Solution Explorer Keeps showing nuget packages I am no longer referencing 从.Net 4.0到4.5的重新定位解决方案-如何重新定位NuGet包? - Retargeting solution from .Net 4.0 to 4.5 - how to retarget the NuGet packages? 引用从也使用其中一些包的项目中使用NuGet包的程序集 - Referencing assemblies that use NuGet packages from a project that also uses some of these packages 更新解决方案中所有项目中的 nuget 包 - Updating nuget packages in all projects in a solution 将.NET项目从一种解决方案复制到另一种解决方案时,Nuget软件包无法正确还原 - Nuget packages not restoring correctly when Copying and including .NET projects from one solution to another 覆盖解决方案中项目的nuget包还原目录 - Override nuget package restore directory for a project in the solution VS解决方案使用git子模块时如何解析nuget包 - How to resolve nuget packages when using git submodules for VS Solution 添加到解决方案后,NuGet 包将恢复/安装到多个位置 - When added to solution NuGet packages restore/install to multiple locations 需要使用nuget在vs 2015中一次安装所有软件包 - Need to install all packages at once for a solution in vs 2015 using nuget 为解决方案文件夹外的项目设置NuGet包文件夹 - Setup NuGet packages folder for project outside solution folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM