为 .Net 使用 OR 工具 NuGet
简介
本指南将通过一个简单的操作说明,帮助您开始使用 .Net 中的 OR-Tools
示例。
虽然这些说明可能也适用于其他 Linux 版本
仅在满足以下要求的计算机上进行了测试:
- Alpine Edge 64 位 (x86_64)
- Centos 7 LTS 64 位 (x86_64)
- Debian SID 64 位 (x86_64)
- Debian 11 (bullseye) 64 位 (x86_64)
- Fedora 38 64 位 (x86_64)
- Fedora 37 64 位 (x86_64)
- OpenSuse Leap 64 位 (x86_64)
- Ubuntu 24.04 64 位 (x86_64)
- Ubuntu 22.04 LTS 64 位 (x86_64)
- Ubuntu 20.04 LTS 64 位 (x86_64)
前提条件
以下各部分介绍了安装 OR-Tools 的前提条件。
.Net Core SDK 3.1 及更高版本
接下来,安装 .Net Core SDK 3.1 或更高版本。为此,
打开一个终端窗口并输入:
apk add dotnet6-sdk
ref: https://learn.microsoft.com/en-us/dotnet/core/install/linux-alpine
sudo rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm
sudo yum install -y dotnet-sdk-6.0
参考:https://learn.microsoft.com/zh-CN/dotnet/core/install/linux-centos#centos-7
<ph type="x-smartling-placeholder"></ph>
在安装 .NET 之前,请运行以下命令以添加 Microsoft
将软件包签名密钥添加到可信密钥列表中,然后将软件包添加到
存储库
wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt update
sudo apt install -y dotnet-sdk-6.0
参考:https://learn.microsoft.com/zh-CN/dotnet/core/install/linux-debian
sudo dnf install -y dotnet-sdk-6.0
参考:https://learn.microsoft.com/zh-CN/dotnet/core/install/linux-fedora
<ph type="x-smartling-placeholder"></ph>
sudo dnf install -y dotnet-sdk-6.0
参考:https://learn.microsoft.com/zh-CN/dotnet/core/install/linux-fedora
<ph type="x-smartling-placeholder"></ph>
在安装 .NET 之前,请运行以下命令以添加 Microsoft
将软件包签名密钥添加到可信密钥列表中,然后将软件包添加到
存储库
sudo zypper install libicu
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
wget https://packages.microsoft.com/config/opensuse/15/prod.repo
sudo mv prod.repo /etc/zypp/repos.d/microsoft-prod.repo
sudo chown root:root /etc/zypp/repos.d/microsoft-prod.repo
然后,您可以使用以下命令安装 .Net SDK:
sudo zypper install -y dotnet-sdk-6.0
参考:https://learn.microsoft.com/zh-CN/dotnet/core/install/linux-opensuse
<ph type="x-smartling-placeholder"></ph>
sudo apt install -y dotnet-sdk-6.0
参考:https://learn.microsoft.com/zh-CN/dotnet/core/install/linux-ubuntu
<ph type="x-smartling-placeholder"></ph>
sudo apt install -y dotnet-sdk-6.0
参考:https://learn.microsoft.com/zh-CN/dotnet/core/install/linux-ubuntu
<ph type="x-smartling-placeholder"></ph>
sudo apt install -y dotnet-sdk-6.0
参考:https://learn.microsoft.com/zh-CN/dotnet/core/install/linux-ubuntu
获取 .Net 示例代码
示例代码位于
dotnet_or-tools 代码库。
以 zip 文件的形式下载代码库
并将其解压缩,或者克隆代码库:
git clone -b v9.10 --depth 1 https://github.com/or-tools/dotnet_or-tools
切换到示例目录:
cd dotnet_or-tools
构建示例
在 dotnet_or-tools
目录下:
使用以下命令构建项目:
dotnet build -c Release
运行示例
在 dotnet_or-tools
目录下:
使用以下命令运行二进制文件:
dotnet run -c Release
恭喜!您刚刚使用 OR-Tools 运行了一个应用,
开始使用 OR 工具。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-22。
[null,null,["最后更新时间 (UTC):2024-08-22。"],[[["This guide provides instructions for getting started with OR-Tools in .Net on various Linux distributions, including Alpine, Centos, Debian, Fedora, OpenSuse, and Ubuntu."],["Before starting, you need to have .Net Core SDK version 3.1 or higher installed, and instructions are provided for different Linux distributions."],["To run the OR-Tools example, you need to download or clone the `dotnet_or-tools` repository, build the project using `dotnet build -c Release`, and then run the binary using `dotnet run -c Release`."],["This guide focuses on providing a simple working example and directs you to further resources for a deeper dive into OR-Tools."]]],["This guide outlines installing OR-Tools in .Net on various Linux distributions. Users must first install .Net Core SDK 3.1 or higher using distribution-specific commands (e.g., `apk add dotnet6-sdk` for Alpine, `sudo apt install -y dotnet-sdk-6.0` for Ubuntu). Next, download the `dotnet_or-tools` repository as a zip file or clone it with git. Subsequently, navigate to the `dotnet_or-tools` directory, build the project with `dotnet build -c Release`, and run it with `dotnet run -c Release`.\n"]]