NuGet添加外部引用
我的项目有一个.nuspec文件,它引用了项目(包括我的包)需要引用的第三方DLLNuGet添加外部引用,nuget,nuget-package,Nuget,Nuget Package,我的项目有一个.nuspec文件,它引用了项目(包括我的包)需要引用的第三方DLL <?xml version="1.0"?> <package > <metadata> <id>$id$</id> <version>$version$</version> <title>$title$</title> <authors>$author$</authors> <
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Locked against log4net 1.2 - less than 1.2.11 which has breaking changes</releaseNotes>
<copyright>Copyright 2012 blah blah</copyright>
<dependencies>
<dependency id="log4net" version="[1.2,1.2.11)" />
<dependency id="My.Other.Project" />
</dependencies>
<references>
<reference file="Third.Party.dll" />
</references>
$id$
$version$
$title$
$author$
$author$
假的
$description$
针对log4net 1.2锁定-小于1.2.11,具有突破性更改
版权所有2012等等
如果我尝试从包含.csproj和.nuspec文件的目录中运行nuget.exe pack My.Project.csproj,我会得到
无效的程序集引用“Third.Party.dll”。确保lib目录中存在名为“Third.Party.dll”的文件
我创造了
.\lib
.\bin\Debug\lib
.\obj\lib
文件在这三个地方。它真正想要lib文件夹在哪里?元素定义了安装包时将添加到项目中的引用。您缺少的是定义文件的部分,这些文件是使用元素完成的包的一部分。因此,您的.nuspec文件应该如下所示:
<?xml version="1.0"?>
<package>
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Locked against log4net 1.2 - less than 1.2.11 which has breaking changes</releaseNotes>
<copyright>Copyright 2012 blah blah</copyright>
<dependencies>
<dependency id="log4net" version="[1.2,1.2.11)" />
<dependency id="My.Other.Project" />
</dependencies>
<references>
<reference file="Third.Party.dll" />
</references>
</metadata>
<files>
<file src="lib\Third.Party.dll" target="lib"/>
</files>
</package>
$id$
$version$
$title$
$author$
$author$
假的
$description$
针对log4net 1.2锁定-小于1.2.11,具有突破性更改
版权所有2012等等
唯一的区别是元数据元素后面的files元素。我遇到了同样的问题,下面是我如何解决的。对我来说似乎很奇怪,但它看起来很有效,我不需要用这种方式为我的第三方程序集创建nuget包 我的.nuspec如下所示:
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Some release notes</releaseNotes>
<copyright>Copyright 2012</copyright>
<tags>some,tags</tags>
<references>
<reference file="thirdparty.dll"></reference>
<reference file="ThisAssemblyName.dll"></reference>
</references>
</metadata>
<files>
<file src="web.config.transform" target="content"/>
<file src="lib\net40\thirdparty.dll" target="lib\net40"/>
</files>
</package>
$id$
$version$
$title$
$author$
$author$
假的
$description$
一些发行说明
版权所有2012
一些,标签
如您所见-我必须添加一个文件节点以将第三方dll复制到目标lib\net40(在我的示例中)文件夹。然后,我必须为thirdparty.dll以及这个NuGet包正在创建的程序集添加“reference”节点。我觉得Matt Ward的解决方案应该是正确的,但在我添加(冗余)引用节点之前,它对我不起作用
我希望这有帮助
谢谢
穆斯塔法哇,它对我很管用。需要引用当前程序集。谢谢:)我还需要引用当前程序集。非常感谢Mustafakidd。根据文档所述,添加
元素的行为意味着lib文件夹中的程序集将不再作为引用自动添加到目标项目中。通过使用该元素,您表示希望显式指定引用,因此也必须指定原始程序集。没有解释为什么在没有
元素的情况下,我在lib文件夹中的额外DLL不会自动添加为引用…好的,显然对lib文件夹根目录中DLL的支持已被弃用。除此之外,对我有效的是添加对self项目的引用,正如Mustafakidd所提到的;我试着把它放进去,但它不喜欢。仔细重读文件规范,然后回来看看你的文章,这是正确的方法。所以要小心;是一位同龄人