简体   繁体   中英

How to target Mono framework from VS2015?

I want to deploy ASP.NET web app on Linux with mono installed.

From what I know Mono is a targeting platform similar to .DNX 4.5.1 or .DNX Core 5.0. So I need somehow add it to targeting platforms in my project to compile and debug the project against it.

Surprisingly, I didn't managed to find any instructions. I'm creating a new ASP.NET 5/vNext project, and all I see is 4.5.1 and Core 5.0 compile targets. How to add Mono to that list?

Compile from Visual Studio and target Mono

As extract from here

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 and it's for VS 2012 (but it should work for other versions).

  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.5\\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

<?xml version="1.0" encoding="utf-8"?>
<FileList  Redist="Mono-4.5" Name="Mono 4.5 Profile" RuntimeVersion="4.5" ToolsVersion="4.0" > </FileList>

There was some Mono product/Mono for VS that integrates Mono into VS, but now there is none.

You should target .NET Core 5 in this case, as it is going to be the ultimate solution.

Mono does still provide some support for ASP.NET 4.* projects, but it would be difficult to assert compatibility as you need to deploy to Mono on Linux to verify. Even in those cases your project should target full .NET Framework just like what you do in the past. There is no Mono specific profile to target.

Have a look at pythonnet solution and projects which target multiple CLR runtimes:

https://github.com/pythonnet/pythonnet/blob/master/pythonnet.sln

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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