简体   繁体   English

添加到解决方案后,NuGet 包将恢复/安装到多个位置

[英]When added to solution NuGet packages restore/install to multiple locations

I'm using Visual Studio 2017, building a .Net framework (not core) v4.6.1 ASP.Net MVC project and when I added packages to my single project inside my solution the packages are seemingly restoring/installing to multiple different locations.我正在使用 Visual Studio 2017,构建一个.Net 框架(非核心)v4.6.1 ASP.Net MVC 项目,当我将包添加到我的解决方案中的单个项目时,这些包似乎正在恢复/安装到多个不同的位置。 I am installing packages from multiple feeds, some are internal to my company and others are public.我正在从多个源安装软件包,有些是我公司内部的,有些是公开的。

Some packages are located at my solution root and others seemingly are landing at %userprofile%.nuget\\packages\\有些包位于我的解决方案根目录,而其他包似乎位于 %userprofile%.nuget\\packages\\

One package even installed and its hintpath was in a completely different location from the two of them.甚至安装了一个软件包,其提示路径与两个软件包位于完全不同的位置。 The package was installed there but I don't know why it didn't install to what I consider the solution's local package folder.该软件包已安装在那里,但我不知道为什么它没有安装到我认为解决方案的本地软件包文件夹中。

I'm not sure if these are the right questions to ask yet, but these are what I'm trying to answer for now:我不确定这些问题是否正确,但这些是我现在要回答的问题:

  1. For VS2017, .Net framework, ASP.Net MVC what is the default package install location?对于 VS2017、.Net 框架、ASP.Net MVC,默认包安装位置是什么?
  2. How do I specify which feed a package comes from for CI/CD purposes?出于 CI/CD 目的,我如何指定包来自哪个提要?
  3. Does NuGet look for packages already installed on my computer? NuGet 是否会查找已安装在我的计算机上的软件包?
  4. If yes, where does NuGet look for packages and where can I find its list of locations it looks for.如果是,NuGet 在哪里查找包以及在哪里可以找到它查找的位置列表。

Thanks!谢谢!

1.For VS2017, .Net framework, ASP.Net MVC what is the default package install location? 1.对于VS2017、.Net框架、ASP.Net MVC默认包安装位置是什么?

It depends on which package management method you using.这取决于您使用的包管理方法。 If you are use package.config , the default package install location is solution root, if you are use PackageReference , the default package install location is %userprofile%.nuget\\packages\\ .如果你使用package.config ,默认包安装位置是解决方案根目录,如果你使用PackageReference ,默认包安装位置是%userprofile%.nuget\\packages\\ That is the reason why you added packages to single project inside the solution the packages are seemingly restoring/installing to multiple different locations.这就是为什么您将包添加到解决方案中的单个项目的原因,这些包似乎正在恢复/安装到多个不同的位置。 You can unload and edit your project, check the project file .csproj , you will find following:您可以卸载并编辑您的项目,检查项目文件.csproj ,您会发现以下内容:

  <ItemGroup>
    <PackageReference Include="xxxxx">
      <Version>x.x.x</Version>
    </PackageReference>
  </ItemGroup>

To resolve this issue, you can accept the advice of Lex.要解决此问题,您可以接受 Lex 的建议。 If you want to unify, make the choice and change the files.如果要统一,请做出选择并更改文件。 You can uninstall those packages which using PackageReference (or package.config), then change the nuget settings(Tools->Options->NuGet Package Manager->General-> Default package management format ->Packages.config), then reinstall those packages, make sure they use a uniform form.您可以卸载那些使用PackageReference (或 package.config)的包,然后更改 nuget 设置(Tools->Options->NuGet Package Manager->General-> Default package management format ->Packages.config),然后重新安装这些包,确保它们使用统一的形式。

2.How do I specify which feed a package comes from for CI/CD purposes? 2.如何指定包来自哪个提要用于 CI/CD 目的?

You can not do such things and you do not need to do things.你不能做这样的事情,你也不需要做这些事情。 As we know, when we install nuget packages from multiple feeds, all the packages are downloaded to the local host, Visual Studio will use those packages on the local, Nuget does not care which feed it comes from.我们知道,当我们从多个提要安装 nuget 包时,所有包都会下载到本地主机,Visual Studio 会在本地使用这些包,Nuget 并不关心它来自哪个提要。

3.Does NuGet look for packages already installed on my computer? 3.NuGet 会查找我电脑上已经安装的包吗? 4.If yes, where does NuGet look for packages and where can I find its list of locations it looks for. 4.如果是,NuGet 在哪里查找包以及在哪里可以找到它查找的位置列表。

Yes, you can use the command line nuget locals all -list to find its list of locations.是的,您可以使用命令行nuget locals all -list来查找其位置列表。

See Managing the global packages, cache, and temp folders for some more details.有关更多详细信息请参阅管理全局包、缓存和临时文件夹

Hope this helps.希望这可以帮助。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM