c# - 从 .Net Standard 项目和 Native dll 创建一个 nuget 包

标签 c# c++ nuget interop .net-standard-2.0

我有一个引用 C++ dll 的 .Net 标准项目

现在我正在使用 DllImport 让它工作。

我想创建一个 Nuget 包,其中包含所有目标的相关 dll。

我想我必须为所有目标(Windows x64、Windows x86、Linux 等)构建 C++ 库。很好。

现在我需要以某种方式将它们全部打包到一个 nuget 包中,但我不确定该怎么做)

How to add C++ library in a .NET Core project是相似的,但对于具有新样式 csproj 并使用 dotnet cli 而不是 nuget cli 的 .Net Standard 项目,答案是不正确的。它也没有解释这如何与多个目标一起工作。

此外,我是保留我的 DllImports,还是需要更改它们?现在我使用 dll 的绝对文件路径:

internal const string DLL = "D:\\filepath\\mydll.dll";

[DllImport(DLL)]
internal static extern int MyMethod();

最佳答案

您可以为多个目标创建 nuget 包,例如 this并将 c++ dll-s 添加为 content因此它将在编译期间被复制到构建输出文件夹,您可以使用 DLLImport

关于c# - 从 .Net Standard 项目和 Native dll 创建一个 nuget 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54020139/

相关文章:

asp.net-core - .Net Core Nuget 包 - 将文件复制到包使用者 wwwroot

c# - 使用 AutoFixture 生成测试数据 : resolving ICollection<T> without mentioning every single T

c# - 使用 BinaryFormatter 反序列化我的序列化数据时出现异常

c++ - GCC#error 不会破坏进一步的编译

c++ - C++ 应用程序的仪表控制

azure-devops - 从 csproj 获取 Azure DevOps 中 Nuget 包步骤中的版本号

c# - 将 asp.net 表单 View 从另一个页面更改为插入模式

c# - 查看excel中是否有隐藏列

c++ - 通过 Xcode 调试使用 CGAL 的代码

c# - 如何在项目中使用 T4 自定义脚手架?