为 .Net 使用 OR 工具 NuGet

简介

本指南通过一个简单的工作示例帮助您开始使用 .Net 中的 OR-Tools。

虽然这些说明可能也适用于其他 MacOS 变体,但我们只在满足以下要求的计算机上测试过它们:

  • MacOS 13.0.1 (Ventura) Intel 64 位 (x86_64)
  • MacOS 13.0.1 (Ventura) M1 (arm64)

前提条件

以下部分介绍了安装 OR-Tools 的前提条件。

Xcode 命令行工具

您必须安装 Xcode 命令行工具。为此,请打开 /Applications/Utilities/ 中的终端,然后输入:

xcode-select --install

点击“安装”以下载并安装 Xcode 命令行工具。您无需从 App Store 中“获取 Xcode”。如果您的互联网连接速度较慢,可能需要很长时间才能完成

验证您是否已成功安装 Xcode 命令行工具:

xcode-select -p

您应该会看到:

/Library/Developer/CommandLineTools

Homebrew

如需安装其余的必备组件,我们建议您首先安装“missing package manager for macOS”(适用于 macOS 的缺失软件包管理器,也称为 Homebro)。为此,请打开终端窗口并输入:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew update

如需验证您是否已成功安装 Breder,请执行以下操作:

brew --version

您应该会看到:

Homebrew 1.6.9-8-g25542d7
Homebrew/homebrew-core (git revision 0e0c84; last commit 2018-06-20)

.Net 6.0 SDK

您必须安装 .Net 6.0 SDK。

安装 HomeBREAK 后,您可以打开终端窗口并输入以下代码来安装 dotnet-sdk 软件包:

brew cask install dotnet-sdk

您可以使用以下命令测试 dotnet CLI 是否已正确安装:

dotnet --info

获取 .Net 示例代码

示例代码位于 dotnet_or-tools 代码库中。

  1. 下载 ZIP 文件形式的代码库并将其解压缩,或克隆代码库:

    git clone -b v9.9 --depth 1 https://github.com/or-tools/dotnet_or-tools
    
  2. 切换到示例目录:

    cd dotnet_or-tools
    

构建示例

dotnet_or-tools 目录中:

使用以下命令构建项目:

dotnet build -c Release

运行示例

dotnet_or-tools 目录中:

使用以下命令运行二进制文件:

dotnet run -c Release

恭喜!您刚刚使用 OR 工具运行应用,可以开始使用 OR 工具了。