我有一个C ++ / CLI DLL,可以连接第三方本机DLL。我想把它打包成Nuget。
我关注了this official MS guide,this blog post和read through this other question。
这就是我所做的:
首先,我创建了正确的nuspec文件:
<?xml version="1.0"?>
<package >
<metadata>
<id>CPlusPlusNativeIFace</id>
<version>1.0.4</version>
<title>CPlusPlusNativeIFace</title>
<authors>Jens Rabe</authors>
<owners>Who owns that</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A DLL that makes a native third-party DLL available to .net</description>
<releaseNotes>foo</releaseNotes>
<copyright>errm...</copyright>
<tags>foo bar</tags>
</metadata>
<files>
<file src="..\Release\**" target="runtimes/win-x86/lib/net461" />
<file src="..\x64\Release\**" target="runtimes/win-x64/lib/net461" />
<file src="DummyAny\**" target="ref\net461" />
</files>
</package>
然后,我为版本x86和版本X64编译了DLL。然后,我创建了DummyAny
文件夹,将x86的内容复制了其中一个,并使用了corflags
实用程序,如链接2和3所示,以剥离32位标志。
当我现在nuget pack
和nuget add
,并尝试在另一个项目中引用该程序包时,我总是得到:
Could not install package 'CPlusPlusNativeIFace 1.0.4'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
我再次检查了文件是否正确:
runtimes/win-x86/lib/net461
中有x86的东西runtimes/win-x64/lib/net461
中有x64的东西但是我仍然无法加载软件包。
我还尝试将CPU特定的DLL放入ref/net461
和runtimes/win-x86/native
中都无济于事。
我还想念什么?不适用于基于.net Framework构建的C ++ / CLI项目吗?
答案 0 :(得分:0)
原来,官方的MS文档在这里不可用。
This question在这里/被列为“相关”,那里的公认答案对我有用。我以the example project on Github作为参考。
这就是我的工作方式:
$(ProjectDir)bin\$(Platform)\$(Configuration)\
<?xml version="1.0"?>
<package >
<metadata>
<id>CPlusPlusNativeIFace</id>
<version>1.0.5</version>
<title>Third Party Proxy</title>
<authors>Jens Rabe</authors>
<owners>foo</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>bar</description>
<releaseNotes>Further experimenting with nuget</releaseNotes>
<copyright>baz moo</copyright>
<tags>quux bletch</tags>
</metadata>
<files>
<file src="bin\Win32\Release\**" target="build\x86" />
<file src="bin\x64\Release\**" target="build\x64" />
<file src="bin\Win32\Release\**" target="lib\net461" />
<file src="CPlusPlusNativeIFace.props" target="build\net461" />
</files>
</package>
CPlusPlusNativeIFace.props
,其中包含以下内容:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Reference Include="CPlusPlusNativeIFace" Condition="'$(Platform)' == 'x86'">
<HintPath>$(MSBuildThisFileDirectory)..\x86\CPlusPlusNativeIFace.dll</HintPath>
</Reference>
<Reference Include="CPlusPlusNativeIFace" Condition="'$(Platform)' == 'x64'">
<HintPath>$(MSBuildThisFileDirectory)..\x64\CPlusPlusNativeIFace.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
现在我可以做nuget pack CPlusPlusNativeIFace.nuspec
了,我得到了一个正确安装的Nuget软件包。