简体   繁体   English

如何编译在 Linux 上使用的 C# 项目?

[英]How to Compile a C# Project for Use on Linux?

I downloaded a C# project from github and compiled it with Visual Studio using the dotnet build command and apparently everything went well.我从 github 下载了一个 C# 项目,并使用dotnet build命令用 Visual Studio 编译了它,显然一切顺利。 But I can't use it on Centos, not even using Mono.但是我不能在Centos上使用它,甚至不能使用Mono。 Which command should I use to compile a C# project in VisualStudio for use on Linux?我应该使用哪个命令在 VisualStudio 中编译 C# 项目以便在 Linux 上使用? I used dotnet build which generated me a project with.exe file and I tried to run it with Mono and I got this error File does not contain a valid CIL image.我使用dotnet build为我生成了一个带有 .exe 文件的项目,我尝试用 Mono 运行它,但我得到了这个错误File does not contain a valid CIL image.

sorry if this is the wrong area to ask对不起,如果这是问错的地方

There are different ways to do it and they depend on what you're trying to achieve.有不同的方法可以做到这一点,它们取决于您想要实现的目标。

From .NET application publishing overview来自.NET 应用程序发布概述

Type类型 Command命令
framework-dependent executable for the current platform.当前平台依赖于框架的可执行文件。 dotnet publish点网发布
framework-dependent executable for a specific platform.特定平台的依赖于框架的可执行文件。 dotnet publish -r --self-contained false dotnet publish -r --self-contained false
framework-dependent cross-platform binary.框架相关的跨平台二进制文件。 dotnet publish点网发布
self-contained executable.自包含的可执行文件。 dotnet publish -r网络发布-r

From the Examples section:从示例部分:

Publish an app cross-platform framework-dependent.发布依赖跨平台框架的应用程序。 A Linux 64-bit executable is created along with the dll file.随 dll 文件一起创建 Linux 64 位可执行文件。 This command doesn't work with .NET Core SDK 2.1.此命令不适用于 .NET Core SDK 2.1。

 dotnet publish -r linux-x64 --self-contained false

You may be interested in Single-file deployment and executable :您可能对单文件部署和可执行文件感兴趣:

Bundling all application-dependent files into a single binary provides an application developer with the attractive option to deploy and distribute the application as a single file.将所有依赖于应用程序的文件捆绑到一个二进制文件中,为应用程序开发人员提供了一个有吸引力的选择,可以将应用程序作为一个文件进行部署和分发。 Single-file deployment is available for both the framework-dependent deployment model and self-contained applications .单文件部署适用于依赖于框架的部署模型和自包含应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM