NuGet 打包和引用 dll [英] NuGet Packaging and referencing dll's

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

问题描述

背景:我有两个名为A"和B"的程序集.A"引用B".A"还引用了一些我认为应该打包在 nupkg 中的其他 dll(Microsoft.Enterprise Library.Data 和 Microsoft Enterprise Library.Common).

Background: I have two assemblies called "A" and "B". ""A" references "B". "A" also references some additional dll's (Microsoft.Enterprise Library.Data and Microsoft Enterprise Library.Common ) that I think should be packaged in the nupkg.

我相信我的 nupkg 包应该包含A"、B"和两个Microsoft Enterprise"程序集的程序集输出,这样当有人安装我的包时,它会给他们直接引用程序集A"和其他三个程序集将可用(但不能直接引用,以便他们的应用程序可以运行.打包非引用 dll 的正确方法是什么?

I believe my nupkg package should contain the assembly output from "A", "B" and the two "Microsoft Enterprise" assemblies so that when someone installs my package it will give them a direct reference to the Assembly "A" and the other three assemblies would be available (but not directly referenced, so that their app would run. What is the correct way of packaging the non references dlls?

尝试 #1:将所有必需的 dll 打包到 \net35 文件夹中根据 NuGet 文档关于references" 元素如果省略此元素,然后应用通常的行为,即引用 lib 文件夹中的每个程序集."

Attempt #1: Packing all required dll's in a \net35 folder According to the NuGet documentation regarding the "references" element "If this element is omitted, then the usual behavior applies, which is to reference every assembly in the lib folder."

因此,我假设通过使用此元素,它将仅包含指定为引用的程序集.如果我还使用文件"元素 <file src=*.dll" target="lib\net35"/> ,情况似乎并非如此.如果我有一个类似的元素这将所有 dll 复制到包中,它导致实现此包的程序集引用 \net35 目录中的所有程序集.这不是我想要做的.我期望只有引用"中指定的程序集有一些魔法将是一个实际被引用,所有其他人将保留在爆炸的 \packages 文件夹中,并且该应用程序将正常工作,因为所有 dll 都位于同一目录中.也许我不正确....

So, I assume that by using this element it will only include the assemblies specified as references. This does not seem to be the case if I also use a "file" element <file src=*.dll" target="lib\net35" />. If I have an element like this that copies all dll's to the package it results in the assembly that implements this package to reference ALL the assemblies in the \net35 directory. This is not what I want to do. I expected some magic that only the assembly specified in "references" would be an actual be referenced and all the others would remain in the exploded \packages folder and the app would work since all the dlls are located in the same directory. Maybe I'm incorrect....

尝试 #2 作为内容添加到项目如果我在打包时将未引用的程序集放入 \content\lib 而不是 lib\net35,这会在项目中创建一个 \lib 文件夹并直接将 \content\lib dll 转储到该项目中,然后强制我们将它们检查到源代码管理中.这可以按照我的意愿工作,编译和运行,但是,我真的不希望这些存储在项目的 \lib 文件夹中.

Attempt #2 Adding as content to project If I place the unreferenced assemblies into \content\lib instead of lib\net35 when packaged this creates a \lib folder in the project and directly dumps the \content\lib dlls into that project which then forces us to check them into source control. This works, compiles and runs as I want but, I really don't want these stored in the \lib folder of the project.

我正在寻找一种解决方案,在该解决方案中,项目获取对A"的引用,并且仍然可以与位于同一位置但未直接引用的其他所需程序集一起运行.似乎尝试 #1 是正确的路径,但也许存在错误?

I am looking for a solution where the project gets the references to "A" and can still run with the to other required assemblies co-located but not directly referenced. It seems like Attempt #1 is the correct path but maybe there is a bug?

仅供参考,我直接将这个作为 NuGet 的问题输入,以查看该团队也有答案.

FYI, I entered this as a issue with NuGet directly to see it that team has an answer as well.

推荐答案

这是 Nuget 2.1 中引入的错误,后来在 2012 年 12 月发布的 Nuget 2.2 版中修复.

This was a bug introduced in Nuget 2.1 and was later fixed in Nuget versions 2.2 which was released in December 2012.

在原始帖子中使用尝试 #1 现在可以正常工作.

Using Attempt #1 in original posting now works correctly.

这篇关于NuGet 打包和引用 dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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