问题描述
我有一个Visual Studio C ++项目,该项目在Debug和Release模式下为x86和x64体系结构创建DLL。关于这些规范,我应该将此程序包发布为nuget程序包。所以我的包装里应该有4个DLL。我的问题是如何在我的nuspec文件中指定x86,x64。我在考虑是否应该在每个 file 的 target 字段中指定它,但是我找不到有关如何准确指定这些规范的文档。 我的nuspec文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<Metadata>
<!-- required elements-->
<id>counterpartylookup</id>
<version>0.0.0</version>
<description>counterpartylookup/v140/win32/x86/x64</description>
<authors>***</authors>
<!-- Optional elements -->
<!-- ... -->
<owners>...</owners>
<licenseUrl>***</licenseUrl>
<projectUrl>***</projectUrl>
<dependencies>
***
</dependencies>
<tags> {vc140,win32,x64,x86,dynamic,C++,native}</tags>
</Metadata>
<files>
<file src="..\shared\v140\bin\x64\Release\CounterPartyLookup.dll" target="lib" />
<file src="..\shared\v140\bin\x64\Debug\CounterPartyLookup.dll" target="lib" />
<file src="..\shared\v140\bin\x86\Release\CounterPartyLookup.dll" target="lib" />
<file src="..\shared\v140\bin\x86\Debug\CounterPartyLookup.dll" target="lib" />
</files>
<!-- Optional 'files' node -->
</package>
解决方法
我的问题是如何在nuspec文件中指定x86,x64。
您需要将dll放在名为{platform}-{architecture} \ lib {framework}或{platform}-{architecture} \ native的子文件夹中的runtimes文件夹中。
文件夹结构:
\runtimes
\x86
\Debug
\Release
\x64
\Debug
\Release
nuspec文件如下:
<files>
<file src="..\shared\v140\bin\x64\Release\CounterPartyLookup.dll" target="runtimes\ x64\Release " />
<file src="..\shared\v140\bin\x64\Debug\CounterPartyLookup.dll" target=" runtimes\ x64\Debug " />
<file src="..\shared\v140\bin\x86\Release\CounterPartyLookup.dll" target=" runtimes\ x86\Release " />
<file src="..\shared\v140\bin\x86\Debug\CounterPartyLookup.dll" target=" runtimes\ x86\Debug " />
</files>
相关文档:Architecture-specific folders和Adding the native implementation libraries。
,或者您可以尝试另一个:
1)在您的项目文件夹中创建一个名为<package_id>.targets
的文件。 在您的身边,您应将其命名为counterpartylookup.targets
:
在下面写下这些内容:
<Project>
<ItemGroup Condition="'$(Platform)'=='x64' and '$(Cofiguration)'=='Debug'">
<Reference Include="$(MSBuildThisFileDirectory)..\Reference\x64\Debug\CounterPartyLookup.dll"></Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)'=='x86' and '$(Cofiguration)'=='Debug'">
<Reference Include="$(MSBuildThisFileDirectory)..\Reference\x86\Debug\CounterPartyLookup.dll"></Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)'=='x64' and '$(Cofiguration)'=='Release'">
<Reference Include="$(MSBuildThisFileDirectory)..\Reference\x64\Release\CounterPartyLookup.dll"></Reference>
</ItemGroup>
<ItemGroup Condition="'$(Platform)'=='x86' and '$(Cofiguration)'=='Release'">
<Reference Include="$(MSBuildThisFileDirectory)..\Reference\x86\Release\CounterPartyLookup.dll"></Reference>
</ItemGroup>
</Project>
2)修改您的nuspec文件:
<files>
<file src="..\shared\v140\bin\x64\Release\CounterPartyLookup.dll" target="Reference\x64\Release" />
<file src="..\shared\v140\bin\x64\Debug\CounterPartyLookup.dll" target="Reference\x64\Debug" />
<file src="..\shared\v140\bin\x86\Release\CounterPartyLookup.dll" target="Reference\x86\Release" />
<file src="..\shared\v140\bin\x86\Debug\CounterPartyLookup.dll" target="Reference\x86\Debug" />
<file src="counterpartylookup.targets" target="build"/>
</files>
3)重新打包c ++项目,然后在安装新项目之前,应删除C:\Users\xxx(current user)\.nuget\packages