Using visual studio for developing mono applications - c#

How do I use Visual Studio to develop applications on Mono? Is this possible?

You just build the applications in Visual Studio, and run them under Mono instead of under .NET. The binaries should be compatible... but you'll need to make sure you don't use any libraries which aren't available in Mono - see the Mono Application Compatibility Guidelines.
(According to that page, you need to turn off incremental builds in Visual Studio though - a point I wasn't aware of before :)

See this article on how to run your apps while targeting the mono framework from VS.

Miguel has posted this entry a while ago, so it's quite dated. You can also try this and this (all hail Web Archive!)

Since version 2.0 MonoDevelop supports VisualStudio project/solutions file format. This means that you can use the same code base on Windows with VS and .Net and on Linux with MonoDevelop and Mono. That in my opinion is the best way to go about it. There are no major reasons to run application in Mono on Windows, other than for testing purposes and for that I'd rather set up a virtual machine to test the software in native environment.

I've posted an article on how to integrate Mono 2.8 (the build for .Net 4.0) into Visual Studio 2010 here - there's a link there to another profile built for Mono 2.4 (.Net 3.5) if that's what you're aiming for.
You can integrate the new Mono 2.8 profile with 3 simple steps:
Download the profile itself from here.
Unzip the contents of the profile Zip to one of the following directories:
32-bit systems: C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile
64-bit systems: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile
The "Mono" folder in the ZIP should be directly under the "Profile" directory.
Restart Visual Studio if it had been running, open the properties of the project you want to use with Mono, and select the Mono Profile for 2.8:
Note: You will not be able to select the Mono Profile straight from the New Project dialog box; for some reason, that list of profiles doesn't match. Create your project as a .Net Framework 4.0 project first, and after creation set the project properties to Mono.
If you've upgraded your MonoDevelop install to the latest version (as of today, anyway), this Visual Studio solution & Project file will open with no problem - no changes required at all.
If you encounter the problem that you need .NETFramework,Version=v4.0,Profile=Mono in order to run the application, the trick was to create registry key.
For running Windows 7 x64, it was: HKEY\_LOCAL\_MACHINESOFTWAREWow6432NodeMicrosoft .NETFrameworkv4.0.30319SKUs .NETFramework,Version=v4.0,Profile=Mono
I suppose for x86 it’s HKEY\_LOCAL\_MACHINESOFTWAREMicrosoft.NETFramework v4.0.30319SKUs.NETFramework,Version=v4.0,Profile=Mono
(Where v4.0.30319 would be the version of the current 4.0 framework installed.)

Yes, you can develop on Visual Studio and target Mono (Mono for x86).
Here is an answer I made on all the available possible alternative to compile against Mono on Windows. However, it's focused for Mono x86.
As a summary, let's list the possible choice for VS development:
MonoHelper addin
Mono Profile
For Android/Ios, you can also cross-compile and debug inside Visual Studio with Xamarin addin. Although it's not free for commercial huge applications, there a free version available to make small ones.
Note: For those who wonder why in the world I would like to develop in Visual Studio on Windows, instead of MonoDevelop on Unix, let say that developer experience in MonoDevelop does not compare to VS one (especially when it comes to debugger/refactoring, the last due more to Resharper than to VS itself).

Related

Generate binaries for executing C# Visual Studio script in Linux

this might be a very stupid question but I was asked to provide a solution of a C# code that I wrote in Visual Studio together with "binaries" to run on a Linux or MacOS system.
How can I generate these binaries and how do they work? Does Visual Studio have some option to make them?
Thanks!
You need to target .NET Core, then you can run it on all major operating systems (with some limitations - i.e. there can't be any WPF or Winforms code). Select ".NET 5.0" as target framework. Then right-click the project in VS and choose "Publish". It's easiest to choose "Publish to folder" afterwards. In the options, you can choose the target operating system.

Is it possible to run a Visual Studio for Mac project on Windows?

Can a project made in Visual Studio for Mac be opened and run in Visual Studio on Windows?
I only have access to Mac, so unfortunately I cannot check it by myself.
It depends on the framework and libraries you target. Obviously if you use MonoMac or something with a Mac-specific UI, it'll run only on the Mac, but if you're writing a console app targeting .NET Core, by default it'll run fine on Windows. To write a cross-platform UI, you could try a third-party framework like Avalonia.
Edit: I should add that the .csproj and .sln formats used by Visual Studio for Mac are the same used by VS for Windows, so in general a project or solution for a cross-platform app (.NET Core) or library (.NET Core or .NET Standard) can be read by either Visual Studio.
In fact, I run Parallels with Windows 10 on my Mac with my repos in shared folders and will compile my cross-platform apps from whichever side on which I wish to run them. (There are line-ending considerations and other minor annoyances, but it works.)

Can I program in C# on a Mac?

I want to learn C# for Unity and my personal computer is a MacBook Air. Can I program in C# on a Mac?
Your first option is Microsoft Visual Studio for Mac which was released in 2017. If you're used to VS ide then I suggested you download this.
If not then you can have a look into MonoDevelop. You can download from here
MRE = Mono Runtime Environment
MDK = Mono Development Kit.
MDK = MRE + Extra tools, libraries, .NET PCL (Portable Class Library) profiles, etc.
If you have an application that you want to run that needs Mono you can install just the MRE.
If you are doing development, writing C# applications, whilst you can sometimes get away with just having the MRE installed, you may hit some missing features such as not having the .NET PCL profiles. So I would install the MDK if you are doing development. Reference
Yes, it is. Microsoft has released Visual Studio Code 2017. It works on Windows, Mac OS, and Linux; It is quite nice development text-editor. It works similar to the full-version, available on Windows - with a few draw-backs, and it will allow to write programs, as well as run and test them right on your Mac.
Microsoft Docs offer a quick getting started tutorial and a Hello World program out-of-the-box with the Visual Studio Code.
You will need to install a few dependencies, however. Which may sound kinda of obvious:
Visual Studio Code
.Net Core SDK
C# extension from the marketplace.
I had good luck getting started and Visual Studio got all of the dependencies for me; so I simply went into the program, opened the integrated terminal (View > Integrated Terminal) and ran the command dotnet new console, and boom, a few seconds later I had a Hello World program, written in C#, running on my MacBook Pro.
There is now a Visual Studio for Mac available as a free community version as well as professional and enterprise versions by subscription.
JetBrains also has an IDE for C#, called Rider, that runs on the Mac. If you use IntelliJ or any of their other products you might like it - it feels better to me than MonoDevelop or Visual Studio for Mac. It is a commercial product but JetBrains offers very generous license terms (as in free) for students and open source projects. They also have a substantial discount for startups.
It is possible, but you won't be able to use Microsoft's tools, you'll need to use a third-party program like Xamarin Studio (MonoDevelop).
Edit
at the time of this answer there wasn't a Microsoft tool/IDE that could be used for developing .net / C# programs on a Mac. Now there are two:
Visual Studio Code
Visual Studio for Mac
Note that while everyone mentions Mono and Xamarin, which you should absolutely look into for C# development, Unity works on Mac directly, specifically Mac OSX 10.6+
while both use the C# language, some of the paradigms espoused by Unity are a little different from standard C# development. I personally recommend learning both.
ADDENDUM: Note that MS has recently announced that they'll be moving the standard .NET implementation cross-platform, and are doing so with the help of the Mono team, so while there's currently a confusing dual set of tools, it'll be shifting away from this in the future
It is entirely possible, if you install a version of Windows using Bootcamp you can switch between the two at start up and have the full functionality of both by installing Visual Studio on the Windows partition. Alternatively, you could use VMware such as Virtual Box and use Windows within your Mac OS.

.NET decompiler for Mac or Linux

I need to decompile a small application written in .NET and convert it to C++. I don't have Windows installed and I know there're a number of .NET decompilers for Windows. Since I have only Mac and Linux and don't want to install Windows only to be able to run a decompiler, I wonder, is there any easy way to decompile a .NET application in Mac or Linux? I searched for it and didn't find anything.
Since most of the parts of .NET is open-sourced, ILSpy also works with Linux and Mac.
From project GitHub page:
Decompiler Frontends
Aside from the WPF UI ILSpy (downloadable via Releases, see also
plugins), the following other frontends are available:
Visual Studio 2017/2019 extension marketplace
Visual Studio Code Extension repository | marketplace
ICSharpCode.Decompiler NuGet for your own projects
Linux/Mac/Windows ILSpy UI based on Avalonia - check out https://github.com/icsharpcode/AvaloniaILSpy
Linux/Mac/Windows command line client - check out ICSharpCode.Decompiler.Console in this repository
Linux/Mac/Windows PowerShell cmdlets in this repository
Since VS Code works with Linux and Mac, that front end should work in those operating systems too. Command line client should also work.
In addition, JetBrains has a new IDE for .NET, Rider. It works in Linux and Mac. Rider has a built-in decompiler. Unfortunately, this built-in compiler, dotpeek, is only available for Windows.
Another choice is to use mono decompiler, a tool from monoproject. Try to use it. Note that this is an add-in in MonoDevelop.
There's a variant/fork of ILSpy using Avalonia which is available as a packaged MacOS app.
Download from https://github.com/icsharpcode/AvaloniaILSpy/releases
There are instructions for whitelisting the package (which is unsigned) on the page, e.g.:
There is monodis in command line disassembler for IL in Mono.
It is possible to use it on Linux and macOS even if you already work with .NET 5 or 6.
However you have to install Mono.
You can decompile an EXE using built-in facilities within Visual Studio for Mac [if you are on OSX].
Here's a step by step walkthrough post I wrote!

Why doesn't my GTK# compiled binary (created with MonoDevelop) work on Windows?

I created a C# project using MonoDevelop (Xamarin) on my Mac. From what I've read, it seems that Windows should be able to run the .exe if it has .Net installed. However, no such luck. Any pointers on getting this .exe to run in Windows?
Thanks
From monodevelop, with the project open, click Project, then settings. Under the build flag, click general. Change the target framework to .NET 4.0 Client Profile. Make sure mono is installed on windows.
http://www.go-mono.com/mono-downloads/download.html
Install Visual C++ 2013 redistributable package x86 and gtk# for .net.
See here.

Categories