.net NuGet 将 dll 放在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7018913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:48:54  来源:igfitidea点击:

Where does NuGet put the dll?

.netvisual-studiovisual-studio-2010referencenuget

提问by Vaccano

I am trying to work around NuGet's Source Control limitations.

我正在尝试解决 NuGet 的源代码控制限制

To that end I need to know a bit more about how NuGet works. Lets take a simple example. Say I have a project and I add AutoMapper to it. When I add it where is the dll supposed to be put?

为此,我需要更多地了解 NuGet 的工作原理。让我们举一个简单的例子。假设我有一个项目,并向其中添加 AutoMapper。当我添加它时,dll应该放在哪里?

I ask because it does not seem to be consistent. Sometimes the reference is looking for the dll the "Packages" folder:

我问是因为它似乎不一致。有时参考正在寻找“Packages”文件夹中的dll:

NuGet using packages path

NuGet 使用包路径

and sometimes it is looking in the Debug build output folder:

有时它会在 Debug 构建输出文件夹中查找:

NuGet using Debug path

NuGet 使用调试路径

But in both cases the AutoMapper line in the packages.configfile is the same:

但在这两种情况下,packages.config文件中的 AutoMapper 行是相同的:

First example:

第一个例子:

<?xml version="1.0" encoding="utf-8"?>
<packages>  
  <package id="AutoMapper" version="1.1.0.118" />
  <package id="CommonServiceLocator" version="1.0" />
  <package id="Unity" version="2.1.505.0" />
</packages>

Second Example:

第二个例子:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="NSubstitute" version="1.1.0.0" />
  <package id="AutoMapper" version="1.1.0.118" />
  <package id="CommonServiceLocator" version="1.0" />
  <package id="Unity" version="2.1.505.0" />
</packages>

So what is controlling where it sets up up the reference to? And how to I make it just use the Packages Location? (When it uses the Debug output folder those references fail if you to compile for "Release".)

那么是什么控制着它在哪里设置引用呢?以及如何使其仅使用包位置?(当它使用 Debug 输出文件夹时,如果您为“Release”编译,这些引用将失败。)

Frustrated Note:I have to admit that I am finding NuGet to be a cool idea, but not ready for anything but simple situations. (I am thinking about just going back to having a lib folder with all my dlls in it.)

沮丧的笔记:我不得不承认,我发现 NuGet 是一个很酷的想法,但除了简单的情况外,还没有准备好。(我正在考虑返回一个包含我所有 dll 的 lib 文件夹。)

I can't help but wonder if I am missing something because NuGet has such wide spread adoption. There must be some way to make this work...

我不禁想知道我是否遗漏了什么,因为 NuGet 被广泛采用。必须有某种方法可以使这项工作...

采纳答案by David Ebbo

The short answer is that if you install a NuGet package from VS (either using PowerShell or the dialog), any assemblies that it contains will be referenced from the Packages folder.

简短的回答是,如果您从 VS 安装 NuGet 包(使用 PowerShell 或对话框),它包含的任何程序集都将从 Packages 文件夹中引用。

Note that VS has some quirky behavior such that if you try to build and the packages folder is missing, AND the DLL exists in the bin folder, then it switches the reference to go to the 'bin' folder. Maybe that's what you are seeing?

请注意,VS 有一些古怪的行为,例如,如果您尝试构建并且缺少包文件夹,并且 DLL 存在于 bin 文件夹中,那么它会将引用切换到“bin”文件夹。也许这就是你所看到的?

If that's not the case, and you have a reproducible set of steps that lead to assemblies being referenced NOT from the Packages folder, please open a bug on http://nuget.codeplex.com/. Thanks!

如果情况并非如此,并且您有一组可重复的步骤导致程序集不被 Packages 文件夹引用,请在http://nuget.codeplex.com/上打开一个错误。谢谢!

回答by Hazza

.NET CORE

.NET 核心

In .NET Core nuget packages are now stored in a global location, by default:

在 .NET Core 中,nuget 包现在默认存储在全局位置:

Windows: %userprofile%\.nuget\packages(aka C:\Users\[User]\.nuget\packages)

窗户:(%userprofile%\.nuget\packages又名C:\Users\[User]\.nuget\packages

Linux: ~/.nuget/packages

Linux: ~/.nuget/packages

Additionally, the packages.configwas removed with references now being stored using the <PackageReference>element in the .csprojfile

此外,packages.config删除了现在使用文件中的<PackageReference>元素存储的引用.csproj

You can find out more docs here

您可以在此处找到更多文档



If you cant find the global location, it may have been changed. You can discover it using this command:

如果找不到全局位置,则可能已更改。您可以使用以下命令发现它:

dotnet nuget locals global-packages --list

dotnet nuget locals global-packages --list

If you would like to change the package location to, for example, e:\packages, you can using the following command

例如,如果您想将包位置更改为e:\packages,则可以使用以下命令

dotnet nuget config -Set globalPackagesFolder=e:\packages

Any problems installing nuget packages that I've had have always been fixed by clearing all the cache locations (there are additional places where nuget packages are saved aside from the global location) like so:

通过清除所有缓存位置(除了全局位置之外,还有其他地方可以保存 nuget 包),我一直在解决安装 nuget 包的任何问题,如下所示:

dotnet nuget locals all --clear

回答by Rukshan Samanthilaka

This helps me with this issue

这有助于我解决这个问题

  1. Delete below line in packages.config file

    < package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.3" targetFramework="net45" />
    
  2. Delete folder "Area" - all the files in it

  3. Install Nuget package "PM > Install-Package Microsoft.AspNet.WebApi.HelpPage"

  1. 删除packages.config文件中的以下行

    < package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.3" targetFramework="net45" />
    
  2. 删除文件夹“Area” - 其中的所有文件

  3. 安装 Nuget 包“PM > Install-Package Microsoft.AspNet.WebApi.HelpPage