当有三个或以上的项目时,我们无法将引用的项目DLL包含在其中。
例如,当项目Library1引用项目ReferenceLibrary时,ReferenceLibrary.dll将添加到Library1的引用中。但是,当您将项目Library1引用到测试应用程序项目时,只会将Library1.dll添加到测试应用程序项目的引用中。被引用的项目DLL“Referencelibrary”将被省略。更多详细信息请参见灵活的项目间引用。
如果您想将ReferenceLibrary的DLL嵌入到Library1的NuGet包中,并将其引用到测试应用程序项目中,您可以在添加Library1项目引用后,将ReferenceLibrary项目引用添加到测试应用程序项目中,或者将ReferenceLibrary.dll设置为Library1项目的依赖项,您可以将以下条目添加到Library1.csproj,然后通过NuGet打包Library1并安装此包到测试应用程序:
<ItemGroup>
<Reference Include="ReferenceLibrary, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ReferenceLibrary.1.0.0\lib\net461\ReferenceLibrary.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
更新:
如果我们想将ReferenceLibrary的DLL嵌入到Library1的Nuget包中,我们需要确保在打包Library1包时,ReferenceLibrary.dll被包含在内,无论我们如何嵌入这些DLLS。因此,在打包Library1包时,您可以将ReferenceLibrary.dll作为文件添加到Library1.nuspec,并将目标设置为lib文件夹。下面是我的Library1.nuspec:
<?xml version="1.0"?>
<package >
<metadata>
<id>Library1</id>
<version>1.0.0</version>
<authors>xxxx</authors>
<owners>xxxx</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>Test</tags>
</metadata>
<files>
<file src="..\Library1\bin\Debug\Referencelibrary.dll" target="\lib\net461" />
<file src="..\Library1\bin\Debug\Library1.dll" target="\lib\net461" />
</files>
</package>
请注意:您还需要在Library1.nuspec中包含Library1.dll。