简体   繁体   English

Linux Mono C#错误:无法打开程序集“ Bovine.csproj”:文件不包含有效的CIL映像

[英]Linux Mono C# Error: Cannot open assembly 'Bovine.csproj': File does not contain a valid CIL image

I wrote a project in C# on Windows 10 on Visual Studio 2017. I recently decided to switch to Linux Centos 7 and am using mono to compile my code. 我在Visual Studio 2017的Windows 10上用C#语言编写了一个项目。我最近决定切换到Linux Centos 7,并且正在使用mono编译我的代码。 My project currently has over 12 separate cs class files. 我的项目目前有12个以上的单独的CS类文件。 I managed to use the xbuild command to rebuild my csproj file. 我设法使用xbuild命令来重建我的csproj文件。 The file now shows up as an executable in my command terminal. 现在,该文件在我的命令终端中显示为可执行文件。

When I try to run the command: 当我尝试运行命令时:

mono Bovine.csproj Mono Bovine.csproj

I get the error: Cannot open assembly 'Bovine.csproj': File does not contain a valid CIL image. 我收到错误消息:无法打开程序集“ Bovine.csproj”:文件不包含有效的CIL映像。

After some research, I've seen that this error has occurred for other people when they have regular cs files. 经过研究,我发现当其他人拥有常规的cs文件时,就会发生此错误。 Normally, the solution seems to be to use the mcs command to compile the cs file and then run the resulting executable. 通常,解决方案似乎是使用mcs命令来编译cs文件,然后运行生成的可执行文件。 This does not work, as I cannot compile the csproj file. 这不起作用,因为我无法编译csproj文件。 I can't really compile each separate class cs file since they all rely/call each other. 我不能真正编译每个单独的类cs文件,因为它们都相互依赖/调用。

I know for sure that my project compiled and ran on Visual Studio 2017. I also installed mono complete, and am fairly sure that I have all the necessary assemblies. 我肯定知道我的项目已在Visual Studio 2017上编译并运行。我还安装了mono complete,并且相当确定我具有所有必需的程序集。 Does anyone have some insight to the problem? 有人对这个问题有见识吗?

You don't call mono on your project directly. 您不会直接在项目上调用mono The mono command is for running already compiled assembiles (hence the complaint that your XML csproj file does not contain any valid instructions). mono命令用于运行已编译的汇编文件(因此会抱怨您的XML csproj文件不包含任何有效指令)。

You've already compiled the project using xbuild right (though you really should be using msbuild at this point since xbuild is deprecated, and xbuild at this point probably just invokes msbuild anyway)? 你已经编译使用项目xbuild权(虽然你真的应该使用msbuild ,因为在这一点上xbuild已被弃用, xbuild在这一点上可能只是调用msbuild呢)? In that case go find your compiled .exe file (usually in the bin/Debug or bin/Release folder) and run that with the command instead. 在这种情况下,请找到已编译的.exe文件(通常在bin / Debug或bin / Release文件夹中),然后使用命令运行文件。

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

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