I am trying to work around NuGet's Source Control limitations.
我正在尝试解决NuGet的Source Control限制。
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:
and sometimes it is looking in the Debug build output folder:
有时它会查看Debug构建输出文件夹:
But in both cases the AutoMapper line in the packages.config
file 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的广泛采用。必须有一些方法来完成这项工作......
3 个解决方案
#1
18
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有一些古怪的行为,如果您尝试构建并且缺少packages文件夹,并且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/上打开一个错误。谢谢!
#2
13
.NET CORE
.NET核心
In .NET Core nuget packages are now stored in a global location:
在.NET Core中,nuget包现在存储在全局位置:
C:\Users\[User]\.nuget\packages
.
C:\用户\ [用户] \的NuGet \包。
Additionally, the packages.config
was removed with references now being stored using the <PackageReference>
element in the .csproj
file
此外,packages.config已被删除,现在使用.csproj文件中的
#3
0
This helps me with this issue
这有助于我解决这个问题
-
Delete below line in packages.config file
删除packages.config文件中的以下行
< package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.3" targetFramework="net45" />
-
Delete folder "Area" - all the files in it
删除文件夹“区域” - 其中的所有文件
-
Install Nuget package "PM > Install-Package Microsoft.AspNet.WebApi.HelpPage"
安装Nuget包“PM> Install-Package Microsoft.AspNet.WebApi.HelpPage”
#1
18
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有一些古怪的行为,如果您尝试构建并且缺少packages文件夹,并且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/上打开一个错误。谢谢!
#2
13
.NET CORE
.NET核心
In .NET Core nuget packages are now stored in a global location:
在.NET Core中,nuget包现在存储在全局位置:
C:\Users\[User]\.nuget\packages
.
C:\用户\ [用户] \的NuGet \包。
Additionally, the packages.config
was removed with references now being stored using the <PackageReference>
element in the .csproj
file
此外,packages.config已被删除,现在使用.csproj文件中的
#3
0
This helps me with this issue
这有助于我解决这个问题
-
Delete below line in packages.config file
删除packages.config文件中的以下行
< package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.3" targetFramework="net45" />
-
Delete folder "Area" - all the files in it
删除文件夹“区域” - 其中的所有文件
-
Install Nuget package "PM > Install-Package Microsoft.AspNet.WebApi.HelpPage"
安装Nuget包“PM> Install-Package Microsoft.AspNet.WebApi.HelpPage”