NuGet 添加外部引用 [英] NuGet add external reference
问题描述
我的项目有一个 .nuspec 文件,该文件引用了包含我的包的项目需要引用的第三方 DLL.
<包><元数据><id>$id$</id><version>$version$</version><title>$title$</title><authors>$author$</authors><owners>$author$</owners><requireLicenseAcceptance>false</requireLicenseAcceptance><description>$description$</description><releaseNotes>针对 log4net 1.2 锁定 - 低于 1.2.11,其中有重大更改</releaseNotes><版权>版权 2012 等等</copyright><依赖项><dependency id="log4net" version="[1.2,1.2.11)"/><dependency id="My.Other.Project"/></依赖项><参考资料><reference file="Third.Party.dll"/></参考文献>
如果我尝试从包含 .csproj 和 .nuspec 文件的目录中运行 nuget.exe pack My.Project.csproj,我得到 p>
无效的程序集引用Third.Party.dll".确保 lib 目录中存在名为Third.Party.dll"的文件.
我已经创建了.\lib.\bin\调试\lib.\obj\lib
并且文件在所有三个地方.它真的想要 lib 文件夹在哪里?
references> 元素定义了安装包时将添加到项目中的引用.您缺少的是定义作为包一部分的文件的部分,该文件是使用 <文件> 元素.因此,您的 .nuspec 文件应如下所示:
<包装><元数据><id>$id$</id><version>$version$</version><title>$title$</title><authors>$author$</authors><owners>$author$</owners><requireLicenseAcceptance>false</requireLicenseAcceptance><description>$description$</description><releaseNotes>针对 log4net 1.2 锁定 - 低于 1.2.11,其中有重大更改</releaseNotes><版权>版权 2012 等等</copyright><依赖项><dependency id="log4net" version="[1.2,1.2.11)"/><dependency id="My.Other.Project"/></依赖项><参考资料><reference file="Third.Party.dll"/></参考文献></元数据><文件><file src="lib\Third.Party.dll" target="lib"/></文件></包>
唯一的区别是元数据元素之后的文件元素.
I have a .nuspec file for my project, which references a third-party DLL that the project including my package needs to reference.
<?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>
If I try to run nuget.exe pack My.Project.csproj from the directory with the .csproj and the .nuspec file, I get
Invalid assembly reference 'Third.Party.dll'. Ensure that a file named 'Third.Party.dll' exists in the lib directory.
I have created .\lib .\bin\Debug\lib .\obj\lib
and the file is in all three places. Where does it REALLY want the lib folder?
The <references> element defines the references that will be added to the project when your package is installed. What you are missing is the part that defines the files that are part of your package which is done with the <files> element. So your .nuspec file should look something like the following:
<?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>
The only difference is the files element after the metadata element.
这篇关于NuGet 添加外部引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!