0
votes

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. My project currently has over 12 separate cs class files. I managed to use the xbuild command to rebuild my csproj file. The file now shows up as an executable in my command terminal.

When I try to run the command:

mono Bovine.csproj

I get the error: Cannot open assembly 'Bovine.csproj': File does not contain a valid CIL image.

After some research, I've seen that this error has occurred for other people when they have regular cs files. Normally, the solution seems to be to use the mcs command to compile the cs file and then run the resulting executable. This does not work, as I cannot compile the csproj file. I can't really compile each separate class cs file since they all rely/call each other.

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. Does anyone have some insight to the problem?

1
First, check if you use the latest Mono (then it should use MSBuild and Roslyn, instead of xbuild and mcs). Second, not everything can be brought to Mono.Lex Li

1 Answers

0
votes

You don't call mono on your project directly. The mono command is for running already compiled assembiles (hence the complaint that your XML csproj file does not contain any valid instructions).

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)? 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.