我們不能包含引用的項目DLL與三個或以上的項目。
例如,當項目Library1引用項目ReferenceLibrary時,ReferenceLibrary.dll將被添加到Library1的引用。但是,當您引用項目Library1以投影測試應用程序時,只有Library1.dll將被添加到測試應用程序項目的引用。被引用的項目DLL「Referencelibrary」將被省略。有關更多詳細信息,請參閱Flexible Project-to-Project References。
如果要嵌入的ReferenceLibrary的DLL文件分享幫助的NuGet包內,並參考測試應用程序的項目,你可以添加ReferenceLibrary項目基準測試應用程序項目中添加引用項目分享幫助 或集ReferenceLibrary後.DLL爲LIBRARY1專案的依賴,你可以添加下面的條目爲Library1.csproj,然後打包分享幫助並安裝該軟件包通過的NuGet來測試應用程序:
<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>
更新:
如果我們想要在Library1的nuget包中嵌入ReferenceLibrary的DLL,我們應該確保ReferenceLibrary.dll包含在Library1包中,而不管我們如何嵌入DLLS。因此,當我們打包Library1包並將目標設置爲lib文件夾時,您可以將ReferenceLibrary.dll添加到Library1.nuspec文件中作爲文件。下面是我的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。
「這樣我就不必發佈2個獨立的nuget包」:爲什麼這對你來說如此重要? –
此問題的任何更新?你能從Leo的建議中獲得有用的信息嗎? –
嗨Jeroen,因爲我通常對我的所有代碼使用分層的方法。我經常做的事情是將我的數據訪問層與其他層分開。因此,在這種特定情況下,我不想發佈單獨的存儲庫nuget軟件包。 – Zorthgo