【发布时间】:2018-03-24 00:15:41
【问题描述】:
为混合模式 C++/CLI 库构建 NuGet 包的正确方法是什么?
我有 32 位和 64 位版本的 dll,以及一个使用它的 ASP.NET Core 应用程序(仅针对完整的 .NET 框架),将为这两个平台构建。该应用的解决方案平台是“AnyCPU”。
我尝试使用 /runtimes/ 文件夹,但 Visual Studio 找不到要编译的托管代码。
目前我有 2 个包,例如“MyLibrary”和“MyLibrary64”,dll 在 /lib/ 文件夹中,在我的 csproj 中有条件 PackageReference,但这感觉不对。此外,当我在 VS 中编译时,我得到:
warning MSB3270: There was a mismatch between the processor architecture of the project
being built "MSIL" and the processor architecture of the reference "MyLibrary.dll", "x86".
This mismatch may cause runtime failures. Please consider changing the targeted processor
architecture of your project through the Configuration Manager so as to align the
processor architectures between your project and references, or take a dependency on
references with a processor architecture that matches the targeted processor architecture
of your project.
这个问题类似,但没有答案: Create NuGet package for C++/CLI (mixed) assembly
更新/澄清:
该应用程序可以在 IIS(64 位)中托管,也可以作为独立的自托管安装应用程序(32 位)运行,因此很遗憾两者都是必需的。
【问题讨论】:
-
Nuget 从未专门支持 C++/CLI 程序集,因此它不会帮助您解决此警告。这是一个真实的,你的项目不太可能运行。 asp.net 应用程序很可能在 64 位模式下运行,并且不能使用该程序集的 x86 版本。 AnyCPU 在这种情况下是相当一厢情愿的,项目的位数必须与本机代码的味道相匹配。请考虑构建 x86 风格是否有任何意义。
-
更新了问题
-
这不是澄清,它只是增加了更多未指明的一厢情愿。 nuget 有用的几率应该很低,只需帮助操作系统找到正确的 DLL:stackoverflow.com/a/2594135/17034
-
我忘了最大的问题,.NETCore 不支持 C++/CLI。
标签: nuget c++-cli nuget-package