Dot-Net-Core
使用 csproj 在 NuGet 包中包含非託管 DLL
我正在開發一個依賴於非託管 DLL 的 .NET Core 2.1 庫。我也想在 NuGet 包中包含非託管 DLL。我遇到的問題是,如果我嘗試指定
.csproj文件中的所有資訊,該dotnet build過程會引發以下警告:warning NU5100: The assembly 'content\lib\subdir\somedll.dll' is not inside the 'lib' folder and hence it won't be added as a reference when the package is installed into a project. Move it into the 'lib' folder if it needs to be referenced.我知道我可以通過編寫一個
.nuspec(事實上,我有)嵌入非託管 DLL。但是,似乎我不需要用最新的.csproj文件格式編寫一個。**問題:**如何使用該
.csproj文件在 NuGet 包中嵌入非託管 DLL?
<ItemGroup><None>在文件中指定.csproj似乎將文件包含在輸出目錄中,但它們不會進入 NuGet 包。<ItemGroup><Content>在文件中指定.csproj會將它們添加到 NuGet 包中,但在 Content 目錄中而不是在 Lib 目錄中。如果我真的必須同時擁有一個
.csproj文件和一個.nuspec文件,那麼將元數據放在哪裡的最佳做法是什麼?在他.csproj的文件中?在.nuspec文件中?維護和同步兩者?工具鏈中有什麼東西可以為我做這件事嗎?我正在使用 Visual Studio Code V1.24 和 .NET Core/dotnet V2.1。
您需要在元素上指定顯式包路徑元數據,以便 dll/so/dylib 文件最終位於包中的正確位置,以便將其辨識為特定於執行時的本機 DLL:
<ItemGroup> <None Include="unmanaged.dll" Pack="true" PackagePath="runtimes\win-x64\native" /> </ItemGroup>