【问题标题】:How to pack an x86 / x64 specific C++/CLI DLL with Nuget?如何使用 Nuget 打包 x86 / x64 特定的 C++/CLI DLL?
【发布时间】:2019-04-15 14:51:39
【问题描述】:

我有一个与第三方本地 DLL 接口的 C++/CLI DLL。我想把它打包成 Nuget。

我关注了this official MS guidethis blog postread 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>

然后我为 Release x86 和 Release X64 编译了 DLL。然后我创建了DummyAny 文件夹,将x86 的内容复制到其中,并使用链接2 和3 中的corflags 实用程序去除32 位标志。

当我现在 nuget packnuget 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 的东西
  • 我有一个 ref/net461 文件夹,其中包含被操纵的 dll

但我仍然无法加载包。

我还尝试将 CPU 特定的 DLL 放入 runtimes/win-x86/nativeruntimes/win-x64/native 中,但无济于事。

我还缺少什么?这不适用于基于 .net Framework 构建的 C++/CLI 项目吗?

【问题讨论】:

    标签: nuget


    【解决方案1】:

    原来官方的MS文档在这里不可用。

    This question 在这里/被列为“相关”,那里接受的答案使它对我有用。我使用the example project on Github 作为参考。

    这就是我的工作方式:

    1. 打开项目属性,进入配置属性/常规,选择所有配置所有平台,并作为输出目录,我指定:$(ProjectDir)bin\$(Platform)\$(Configuration)\
    2. 在发布模式下为 x86 和 x64 重建项目
    3. 将 Nuspec 调整为如下所示:
      <?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>
      
    4. 添加了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 包。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-12
      • 1970-01-01
      • 2011-09-22
      • 2021-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多