我有一个NuGet包,其中包含一个托管DLL和一堆本机DLL。托管DLL使用pinvoke调用本机DLL。我已成功将所有内容打包到具有以下目录结构的NuGet包中:
lib
Managed.dll
build
Unmanaged1.dll
Unmanaged2.dll
MyNuGetID.targets
我的.targets文件看起来像这样
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<NativeLibs Include="$(MSBuildThisFileDirectory)*.*" />
<None Include="@(NativeLibs)">
<Link>%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
到目前为止,我所描述的所有内容都遵循here发现的说明。从我读过的,当visual studio安装这个NuGet包时,它应该在我的.csproj文件中插入一个“Import Project”部分,该部分读入我的.targets文件,然后将我所有的非托管DLL复制到我的bin\Debug
目录。我过去使用Visual Studio 2015成功完成了这项工作,但由于某些原因我使用Visual Studio 2012进行的当前设置无法正常工作。我的NuGet包已经安装,Reference Include=Managed...
部分被添加到我的.csproj文件中,但.targets文件永远不会Import
,我的非托管DLL永远不会被复制。
注意:
答案 0 :(得分:0)
正如我在对我的问题的评论中提到的,我发现NuGet 2.0版附带的Visual Studio 2012不支持将.targets或.props文件放在NuGet包的构建目录中。我必须弄清楚在添加该功能之前人们如何从NuGet包中复制本机DLL。显然,它是使用NuGet包的tools目录中的powershell脚本完成的。这是powershell脚本,它成功地将我的所有本机DLL复制到我的Visual Studio项目的输出目录中:
#File: tools\Install.ps1
param($installPath, $toolsPath, $package, $project)
$nativeBinDirectory = Join-Path $installPath "build"
$projectRoot = $project.Properties.Item("FullPath").Value
$binDirectory = Join-Path $projectRoot "bin\Debug"
Copy-Item $nativeBinDirectory\* $debugDirectory
我的新NuGet包目录结构现在如下所示:
lib
Managed.dll
build
Unmanaged1.dll
Unmanaged2.dll
tools
Install.ps1