如何在 C# 应用程序中嵌入 or-tools?

How to embed or-tools in a C# application?

我正在尝试按照 https://developers.google.com/optimization/introduction/installing.html#windows_binary 中的说明进行操作,以便我可以在我的 C# 应用程序中使用 or-tools。

我卡在了 make all 这一步。我在开发人员命令提示符中,但此命令显示:

'make' is not recognized as an internal or external command,
operable program or batch file.

我尝试下载 GNU make,但也失败了。 make install 表示 "no target",而 make 表示:

process_begin: CreateProcess(NULL, cl /EHsc /MD /nologo /D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS -nologo /O2 -DNDEBUG -DUSE_CBC -DUSE_CLP /D__WIN32__ /Iinclude\src\windows /DGFLAGS_DLL_DECL= /DGFLAGS_DLL_DECLARE_FLAG= /DGFLAGS_DLL_DEFINE_FLAG= /Iinclude /Iexamples -DUSE_GLOP -DUSE_BOP -c examples\cpp\costas_array.cc /Foobjs\costas_array.obj, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [objs\costas_array.obj] Error 2

我还尝试将 bin 文件夹中的 DLL 直接复制到我的项目中。通过这样做,我能够针对它们进行编译,但是当我尝试 运行 时,我得到了一个错误:

System.BadImageFormatException: 'Could not load file or assembly 'Google.OrTools, Version=5.1.6235.37215, Culture=neutral, PublicKeyToken=7a052e3db761d3be' or one of its dependencies. An attempt was made to load a program with an incorrect format.'

我错过了什么?

关于 System.BadImageFormatException:

OrTools 二进制格式在 64 位 dll 中提供。

确保您的项目设置为 64 位:

在 Visual Studio 中,您可以通过右键单击项目 --> 属性 --> 构建、平台目标来查看它:这应该设置为 x64。

如果您在使用 Web 应用程序时遇到同样的问题,只需使用 Tools -> Options -> Projects and Solutions -> Web Projects -> Use the 64-bit version on IIS Express for web sites and projects 在 IIS Express 上启用 64 位