How to compile a Visual Studio C# Project with Mono

前端 未结 5 814
暖寄归人
暖寄归人 2020-12-07 17:22

I\'m new to this, and don\'t know where to start.

I want to compile a Visual Studio C# project with Mono on Linux (by command line).

The main.cs file include

5条回答
  •  一向
    一向 (楼主)
    2020-12-07 18:19

    Mono and .NET Framework are not equivalent in terms of features available.

    For example, Mono provides cross platform functions but doesn't implement some windows linked features provided by .NET Framework. So you can't compile with .NET on windows and expect it to run smoothly on Unix/Mono: It may work but there is a high chance it will fail. In fact, the more complex the program, the highest is the chance (you used something not available in Mono).

    Compilation with command line tool: Xbuild

    If you want to compile a .sln/.csproj from command line against mono, then xbuild (mono clone of MSBuild) is the way to go :

    xbuild mysolution.sln
    xbuild myproject.csproj
    

    The man page of xbuild on Ubuntu.

    xbuild.exe is located in mono installation, most likely in:

    C:\Program Files (x86)\Mono\lib\mono\4.5
    

    Compile from IDE (VS)

    You can compile against Mono on Windows, from Visual studio with MonoHelper addin (using xbuild underneath).

    There is also another solution, which is targeting a "Mono" .NET Framework profile from visual studio. Following steps come from here.

    Note: I've tried to change the location of the profile in 4.5 (but that doesn't work; either vs doesn't find it or it detects it as not installed) so always use the v4.0 directory to install a profile based on v4.0 VM. This limitation and the fact that the "Profile" thing has been discontinued makes me thinks that it won't work for higher version of Tools.

    The same profile trick is being used for Unity by the way.

    1. Create two registry keys:

      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.0,Profile=Mono

      HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.0,Profile=Mono

    2. Make a link to Mono directory inside of Microsoft References Assemblies Directory (you may need to run the following with administrator rights)

      cd "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile" mklink /d Mono "C:\Program Files (x86)\Mono\lib\mono\4.5" cd Mono mkdir RedistList cd RedistList notepad FrameworkList.xml

    3. Edit FrameworkList.xml

    Paste the following inside FrameworkList.xml

    
     
    
    1. Change the framework target in the project application tab within Visual Studio

    Compile with MonoDevelop/Xamarin Studio

    MonoDevelop runs on Unix and on Windows, and you can easily switch from .Net compile/debug/run to Mono compile/debug/run within the IDE. However, while MonoDevelop is quite efficient for a C# seasonal developer, it has not reached yet the power of Visual Studio coupled with Resharper.

提交回复
热议问题