转换 Visual Studio 2017 C# 解决方案/项目以便在 Linux 上与 Mono 一起使用?

Convert Visual Studio 2017 C# solution / project for use with Mono on Linux?

我有一个普通的 C# windows x64 控制台应用程序项目包含在 Visual Studio 2017 解决方案中。它在 Visual Studio 中的 windows 上编译。它的目标是 .NET v4.7.1,不过,我相信它可以在较低的 .NET 版本上编译。

我想使用 Mono 将应用程序移植到 Linux 上的 运行。执行此操作的程序是什么?

我简单地尝试了 运行ning dotnet build 但这给出了错误消息:

user@user-VirtualBox:~/Desktop/svm_compute/svm_compute$ dotnet build
Microsoft (R) Build Engine version 16.0.450+ga8dc7f1d34 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Nothing to do. None of the projects specified contain packages to restore.
/usr/share/dotnet/sdk/2.2.203/Microsoft.Common.CurrentVersion.targets(775,5): error : The OutputPath property is not set for project 'svm_compute.csproj'.  Please check to make sure that you have specified a valid combination of Configuration and Platform for this project.  Configuration='Debug'  Platform='AnyCPU'.  You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project. [/home/user/Desktop/svm_compute/svm_compute/svm_compute.csproj]

Build FAILED.

然后,我试了dotnet build svm_compute.csproj /p:ConfigurationPlatforms=Release /p:Platform="x64",也报错了:

user@user-VirtualBox:~/Desktop/svm_compute/svm_compute$ dotnet build svm_compute.csproj /p:ConfigurationPlatforms=Release /p:Platform="x64"
Microsoft (R) Build Engine version 16.0.450+ga8dc7f1d34 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Nothing to do. None of the projects specified contain packages to restore.
/usr/share/dotnet/sdk/2.2.203/Microsoft.Common.CurrentVersion.targets(1183,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.7.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [/home/user/Desktop/svm_compute/svm_compute/svm_compute.csproj]

Build FAILED.

另一方面,如果我使用 IDE monodevelop 我可以加载解决方案,构建它并 运行 它。但是,这不是很有用,因为我需要能够通过 linux 命令行界面构建它并 运行 它而不使用 IDE...

由于您的项目目标是.Net Framework,您应该使用的构建工具是msbuild(包含在最新版本的mono中,请参考https://www.mono-project.com/download/stable/并安装mono-devel 包裹 linux.

打开一个终端 window,导航到您的项目目录,并尝试使用 msbuild /t:build 构建它,如果您有对 nuget 的引用,请先尝试 msbuild /t:restore .

dotnet 命令仅用于 .Net Core 个项目。