Mono vs .NET in Unity - c#

I use Unity with Visual Studio and it's brilliant. But I'm confused about how exactly .NET, Mono and Unity are related to each other. Are these statements right or wrong?
.NET Framework was not designed to be cross-platform.
The goal of .NET Framework is to design programs in a unified way, and they must all run in a virtual machine.
Mono is an open source version of .NET Framework, designed to be cross-platform. Programs built with it can run wherever the Mono virtual machine is installed.
Programs built with Mono cannot run or are not fully compatible with the .NET virtual machine.
Unity only uses Mono for editing, building, and running games.
Games built with Unity have the Mono framework and/or virtual machine embedded in them.
I don't need to have .NET Framework installed for building or running Unity games.
The C# scripts I wrote in Unity are run by a Mono virtual machine, before and after build time. All the Unity engine public code library is C++ wrapped and not actually C#, thus it is running in a C++ side engine.
The Mono framework tools and library are run in-game with a Mono virtual machine.
DLL built with .NET Framework are not fully compatible with Mono.

.Net frameWork was not designed to be cross plateform.
Depends on whether you wish to include say Linux in that. If you are asking if .NET was originally designed to target Linux then, no. However there is the .NET Compact Framework which allowed .NET code to run the Xbox 360 and Windows Phone.
There is now .NET Core, a free and open source framework which is designed for cross platform, specifically Windows, Mac and Linux.
The .Net frameWork goal is to design programs in a unified way, and they must all run and a virtual machine.
Yes. The correct term is Execution Engine by the way not VM though they both are in the same class. Don't think of the EE as something akin to vmWare where CPU instructions are constantly emulated. .NET like Java and are a form of p-code however .NET assemblies are JIT'd to the current CPU so as to improve performance and run natively on the CPU. [1]
Mono is an open source version of .Net frameWork, designed to be cross plateform. Programs built with it can run wherever there is a mono virtual machine.
Yes. .NET Core has the same claims. [4]
Programs built with mono frameWork can not run, or are not fully compatible with .Net virtual machine.
The Mono Framework across it's many versions is not a 1:1 of the equivalent .NET Framework.
e.g.
Mono has no support for WPF in .NET 3.0 [2]
Mono has no support for WWF in .NET 3.0 [2]
Mono has no support for CodeContracts in .NET 4.0 [2]
Unity only use Mono frameWork, either in editing, building and running games.
Incorrect. Unity also uses Unity Script for composing a game.
However there is a big difference for runtime irrespective of your language choice. When targeting say a web browser via Unity Web Player, there is no .NET/Mono EE. The platform is the Unity Web Player. In this sense .NET/Mono is not required on the target platform. [3]
Games built with Unity have embeded mono framework and /or mono virtual machine.
Incorrect, see above
I don't need to have .Net frameWork for building or running Unity games.
Correct
The C# scripts i wrote in Unity are run by a mono virtual machine, before and after build time. All the Unity engine public code library is c++ wrapped and are not actually C#, thus they are running on c++ side engine.
Incorrect, there is no correlation between what language you choose to use to write your Unity game in and whether or not the .NET/Mono EE is present at runtime.
The mono frameWork tools and library are run in game with a mono virtual machine.
Depends.
On your desktop whilst running the Unity Editor? - Yes
Deployed at running on a smartdevice/browser? - no
Dll built with .Net frameWork are not fully compatible with mono.
Incorrect. It is Mono that may or may not be fully compatible with the equivalent .NET Framework. [2]
See also
1 "Is the CLR a Virtual Machine?", MSDN
2 Compatibility, Mono
3 How does the Unity Web Player work?, Quora
4
.NET Core Framework - Go Cross-Platform with the .NET Framework, MSDN

Related

What are the platforms in the .NET Platform Standard?

Currently trying to learn about the .NET Platform Standard I've found myself quite confused about the idea of "different platforms".
I'll try to make my point clear. What I currently now about the .NET Framework is that .NET is roughly speaking made up of the CLR, the BCL and supporting software to boot the CLR and provide the interface between the virtual machine and the underlying OS.
So when we code using the .NET Framework we indeed target some version of the framework because the types we are using from the BCL come with the framework and so depend on the specific version.
Now, .NET Core is quite different as I understood. It is not all packed together like that. We have the CoreCLR which is a lightweight VM to run the IL, the CoreFX which are the libraries properly organized as NuGet packages and we had up to now the DNX/DNVM/DNU which provided the supporting stuff like booting the CoreCLR and interfacing with the OS.
Anyway, despite if we install the framework on Windows 7, Windows 8 or Windows 10, we code against the framework.
Now, on the .NET Platform Standard spec we see the following definition:
Platform - e.g. .NET Framework 4.5, .NET Framework 4.6, Windows Phone 8.1, MonoTouch, UWP, etc.
Also we see after that a list of platforms, which includes
.NET Framework 2.0 - 4.6
Windows 8
Windows Phone 8.1
Silverlight 4, 5
DNX on .NET Framework 4.5.1 - 4.6
DNX on .NET Core 5.0
Now this confuses me completely. I always though: we code against the .NET Framework and the framework is the framework no matter what.
But here we have these platforms which includes the .NET framework as just one of many platforms. We have for example Windows 8, but wait a minute, running .NET on Windows 8 is not just the same thing as running .NET on any other OS? Why it is separate from the .NET Framework 2.0 - 4.6 platform?
We also have DNX as a specific platform. This makes me wonder: the platform is that "supporting stuff" related to booting the Virtual Machine and providing the interface with the OS? Or the platform includes the Virtual Machine?
Anyway, as can be seen I'm quite confused. What are those platforms indeed and how this relates to my current understanding of the .NET Framework? Also, why .NET Framework 2.0 - 4.6 is described separetely? Isn't everything described here some version of .NET Framework unless .NET Core?
we code against the framework.
Well, sure you are. When you manipulate strings in your code then you'll always use System.String. And it (almost) always behaves the exact same way with the exact same methods and properties.
But displaying the string does have implementation details that you cannot really ignore:
If you want to show it in a Unix terminal on Linux or OSX then you need to target Mono or CoreCLR, the framework implementations that can run on such operating systems.
If you want to show it in a Windows Store app (aka WinRT, aka Windows 8, aka UWP) then it is actually a HSTRING under the hood, an very well hidden detail that you don't have to worry about. But does require an UI gadget, like Windows.UI.Xaml.Controls.TextBlock, a class that is highly specific to WinRT
If you want to show it in a browser then you need to target ASP.NET or Silverlight, framework hosts that were optimized to run on a web server or as an add-in for a browser.
If you want to show it on a device that is powered by a small lithium-ion battery, like a phone, then you'll inevitably have to deal with a framework version that was optimized to use as little power as possible. That does affect the code you have to write, there is a huge difference between code that burns 100 Watts and code that keeps a tiny battery alive for 8 hours. Nothing you can directly see, beyond the need to use async/await a lot, but certainly something that affected the runtime very heavily. Targeting Xamarin or WinRT is required.
If you want to show it on any operating system then you do need to target a framework version that does not use the kind of tricks that .NET uses on Windows to have an EXE launch the CLR virtual machine. That requires dnx.exe, just like you'd use java.exe or python.exe for programs written in Java or Python.
It would be lovely if those implementation details did not matter. But not the way it works in practice, as .NET proliferates and becomes available on more and more devices and operating systems it inevitably also becomes more convoluted. Choose your intended targets early, it is important.
There are many Frameworks (.NET Framework, WinRT, UWP, Silverlight, .NET Core, Windows Phone, Mono, Micro Framework und the old Compact Framework) not just only the .NET Framework.
The new way is to program against a platform standard which supports one or more of this frameworks. The platform standard defines an API which matches one or more frameworks. This means if your application supports platform standard 1.1 you will probably support almost all frameworks. Platform standard 1.4 will support .NET Framework 4.6.x and .NET Core only
Have a look at this document: https://github.com/dotnet/corefx/blob/master/Documentation/architecture/net-platform-standard.md
Now this confuses me completely. I always though: we code against the .NET Framework and the framework is the framework no matter what.
No, there are actually plural .NET frameworks or platforms as you like to call them. Prior to .NET Standard, you used to target a single framework (maybe the full one, currently at version 4.6.3, if you develop web applications or windows services). DLLs targeting a framework are not compatible with another one. I.E. a DLL developed for the full .NET framework cannot be executed on Windows phone 8.1.
These frameworks actually implement a quite small common set of librairies, but also specific libraries for dealing with the platform they are intended for. I.E. libraries for managing a web server hosted on IIS in the full .NET framework, or functions for dealing with a mobile phone in the windows phone 8.1 framework.
Before .NET Standard was the PCL
There was although a workaround, called PCL which stands for "Portable Class Libraries". By using only the small common subset of methods/assemblies in two or more .NET frameworks, one could develop a library that could be included in projects targeting different frameworks. For instance, PCL profile 37 means you want your library to be usable in .NET Framework 4, Silverlight 5, and Windows 8 projects.
Please have a look at this for a list of PCL profiles and their compatibilities (I don't know if it's exhaustive): http://danrigby.com/2014/05/14/supported-pcl-profiles-xamarin-for-visual-studio-2/
Now what about .NET Standard ?
The goal with .NET Standard is to simplify this and get rid of PCLs. Roughly, .NET Standard defines a contract (a set of classes and methods), that will be implemented by all .NET frameworks. If you develop a library that targets .NET Standard, you're sure it can run on all .NET frameworks. It's the basic idea/goal behind it (even though it's a bit more subtle).
Have a look at this for the exact compatibility: https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/#user-content-whats-new-in-net-standard-20
If you look at the compatibility table, you'll see that a library targeting .NET Standard 1.6 is usable as is (no need to recompile it) in .NET Framework 4.6.3 and .NET Core 1.0 applications.
In other words, we can say that .NET Framework 4.6.3 and .NET Core 1.0 both implement the .NET Standard 1.6 contract: its classes and methods.
If you also want your DLL to be usable in a windows phone 8.1 project, you'll have to target .NET Standard 1.2, which offers less functions than .NET Standard 1.6 (no System.Net.Sockets for instance).
See here for a list of available namespaces in each version of .NET Standard https://github.com/dotnet/corefx/blob/master/Documentation/architecture/net-platform-standard.md#user-content-list-of-net-corefx-apis-and-their-associated-net-platform-standard-version

Create a standalone exe without the need to install .NET framework

I'm a student and at the moment i'm doing an internship at a company. This internship is about analysing a project. For this project I have made a demo to show to the Marketing director. The demo I have made is a simple project created in Visual Studio 2010 in c# with Windows Forms and a connection to an Access database.
So now i have to show this demo to this director in a presentation but after this presentation the director wants the project on his computer so he can try and use it. The problem is now that the computers here in this company don't have .NET framework 4.0 and the computers are so protected over here that we can't install anything new. To install something you have to go through a procedure that takes weeks.
I have looked al over the internet but all i find is how to install the .NET framework.
Is there any possible way that I can create an standalone exe without the need to install .NET framework? Please help!
If you want to execute an application that is developed using Net Framework 4, you will need to have installed .Net Framework 4 on client computer.
Your application is compiled in CIL (Common Intermediate Language), so it needs to be interpreted by the framework engine.
It is the same if you want to execute a Java program. You will have to install the Java Machine.
The only way you don't need to install frameworks is programming native applications with C, C++.
C# now supports this with .NET Native.
Instead of compiling to intermediate language, it will compile to native code and run with statically linked .NET libraries. Therefore, there will be no .Net Runtime requirements for end-users.
https://msdn.microsoft.com/en-us/vstudio/dn642499.aspx
https://msdn.microsoft.com/en-us/library/dn584397(v=vs.110).aspx
Only works for Windows 10
You can't build a C# executable without .NET Framework. Even if some resources indicate that you can, that only works in theory.
But you could use an older version of .NET Framework like .NET 4.0. If this doesn't work for you, you have to choose a language like C++ which doesn't require CLR at all.
Update 2018:
Do not target .NET 2.0 or 3.5. It's not compatible with the 4.x version. However, .NET 4.0 targeted binaries work with .NET Framework 4.0, 4.5, 4.6, 4.7 and so on. So to reach maximum compatibility, compile with .NET 4.0. You will have to accept that some features will not be available, however, your binary will run virtually anywhere.
(2018: By now, .NET 2.0 - 3.5 has much lower distribution than 4.x)
Delphi is your solution, deploy native bin executables
YES, THIS IS POSSIBLE!
At least 3 ways exist:
1.you can check all OSes that you planning to run your app and build with such version of .NET. As Windows have a built-in framework libs.
Vista -.NET v3.0 -- All service packs
Windows 7 - .NET v3.5 -- All versions and service packs
Windows 8 - .NET v4.0 [Best choice if you are not sure]
Windows 8.1 - .Net v4.5
Windows 10 - .Net v4.6
as they are already pre-installed by default -- no extra install will be needed.
2.For windows 10 you can compile it into native code (but not into CIL) with ".NET Native". This is means that there are no .Net Framework will be needed for apps.
3.There is Turbo Studio (earlier Spoon and earlier XenoCode) that can wrap everything that your app needs and runs it in as a standalone.
From their site:
Turbo Studio
Run .NET Without .NET. Easily embed runtime dependencies such as .NET, Java, and SQL directly into virtual applications. Launch reliably on any desktop, regardless of underlying component installs.
You can use Mono and statically link you program, so your program don't need .NET CLR runtime and act as standalone program.
Mono Project
In more modern versions of .NET such as 5 and 6 and even with releases of .NET Core it had become a supported scenario to produce what is referred to as a single-file executable as well as a self-contained application.
As I understand it, these technologies take place of and build upon some of the capabilities that had been in the Mono development stack for a while now. Typically I've seen this feature used for applications which would be deployed to servers such as web sites and microservices however it could be used for scenarios such as the one that the original poster illustrates.
Using the .NET SDK publishing (producing the executable) for a single-file executable can be done using a command as the one below which comes directly from the documentation.
dotnet publish -r win-x64 -p:PublishSingleFile=true --self-contained true
For more details see Single file deployment and executable in the Microsoft .NET documentation site.
To be honest, it really isnt a problem nowadays. the .NET framework is found on almost every single computer nowadays, and you can even make a installer with Advanced Installer that silently install the .NET framework on your computer when you are installing the programme.

Can a C# program be cross-platform?

I'm a newbie to programming, and I'm considering using C# to write a VERY simple program that simply edits a text file.
Will it work on Macs and Linux? What will work?
I want to know what makes a program cross-platform?
C# can be compiled for and ran on multiple platforms (Windows, Linux, macOS) by using .NET Core.
Previously, cross-platform development using C# could only be done by using Mono which is a third-party implementation however it is now recommended to use .NET Core as it is developed by Microsoft.
Now C# is fully cross platform and has variety of frameworks and run times.
Java is a language + framework. But C# is just a modern language. C# language features are very powerful, easy to learn. No confusion between framework and language.
C# can be used in following frameworks
.Net core (Multi platform supports Linux, Windows and Mac), mostly used to develop restful services, web applications and enterprise systems
.Net Framework (Windows only), Same as .net core, but has more windows only features
Unity - One of most used game engine to develop games for PC, Sony, Xbox devices etc..
Xamarin - To develop native Mobile apps (Android, IOS, Mac)
.Net standard - Create a library in .net standard use in all above applications
Java - Code once, Ship same file to all platforms
C++, C, Rust - Code once, Compile for specific platform
C# - It is just a language, pick your framework according to requirement.
Most popular applications like Chrome, Firefox uses C++, Rust and they are compiled for each platform. But still they share the majority of code between these platforms. Some games use C++ to share the code between IOS and Android.
For new developers its good to start with NodeJS and C#. Both are easy and can do any type of applications.
It's hard to answer something like that to somebody, which states that he just starts programming, but I'll try to give you an (somewhat simplified) overview: C# is a language, which is compiled into an executable program. The language itself is portable between plattforms, as long as you have a compiler on each target plattform. On Windows you have the "default" .Net implementation and on Linux/Mac you have Mono. To do something useful - like editing files - you have to use some libraries. There is a standard library which is available on each plattform. As long as you use only that functionality, your program will be cross plattform. Obviously is will not be cross plattform, as soon as you use some library specific to a certain plattform. Editing files is part of the standard library, so you can implement such simple tools in a cross plattform way. When choosing a book, you should look for books which focus on the "raw" language and not on Visual Studio or other specific tools.
A new open source release from Microsoft called CoreCLR is cross-platform and can now be used for this
The CoreCLR repo contains the complete runtime implementation for .NET Core. It includes RyuJIT, the .NET GC, native interop and many other components. It is cross-platform, with multiple OS and CPU ports in progress.
-from the CoreCLR repo
I would not recommend c# as the top choice for multiplatform coding. I would recommend python instead it is very easy to run even as a script and works perfectly on all platforms. If you insist on c# be prepared to deal with the same problem explained by Justin Ethier. Python on the other hand, is the same for all platforms, it is super powerful fast and even has wrappers ready to connect to other languages.
C# is cross-platform thanks to .NET Core, but without a cross-platform User Interface library you can only make very basic console programs with it. In order to make cross-platform apps for Windows, Mac and Linux you need a cross-platform User Interface library like Nevron Open Vision
Yes, C# is fully cross-platform thanks to .NET Core.
.NET Core is a free and open-source, managed computer software framework for Windows, Linux, and macOS operating systems. It is the cross-platform successor to the .NET Framework which only run on Windows. The project is primarily developed and supported by Microsoft (through the .NET Foundation).
C# is cross platform and you can run your program in Windows/Linux and Mac. For Linux, though, you need to run it using mono

C# Compiler That Can Generate Linux ARM Executables

I've been looking for some C# compilers for Linux and after a long search I've encountered some projects that are very interesting:
Mono
DotGNU
But I haven't seen any approach on any of those to cross-compile applications to ARM Linux executables(arm-unknown-linux-gnu), so I want to know if there is any way to build ARM Linux executables using C# compilers like those or others.
Have you looked at the .NET Micro Framework?
The .NET Micro Framework is currently supported on ARM architecture processors (including ARM7 and ARM9) and on Analog Devices Blackfin. The Porting Kit is now available along with the source code as a free download under the Apache 2.0 license at the Microsoft Download Center..
And:
In February 2011, Novell posted a preview of the Mono 2.12 C# compiler, the first open source compiler for .NET Micro Framework.
Mono is capable of producing non JIT, native execution binaries for ARM. They integrated this into an SDK for the iPhone http://monotouch.net/ .

CLR IN MOBILE ----is it possible to use virtual machine on mobile os

as jvm makes java as plateform independent is it possible with CLR to make .net framework supported languages like c# plateform independent on mobile
Yes, you can use the Mono CLR. Mono is the open source implementation of C#, .NET BCL and the CLR.
MonoTouch runs on the iPhone
MonoDroid runs on Android devices
Yes-ish. At the tooling level, see MonoDroid, MonoTouch or the WP7 tools. However, in each case you are using the language to target a specific mobile platform. You may need different UI code for each, even if the core code is shared.
.NET Compact Framework works on mobile devices (and has for about 8 years now). .NET is also cross-platform (kind of) through the Mono and MonoTouch projects.
Technically, yes, but each handset has it's own limitations that may not make it very feasible.
If you look at the mono-project, it's a portable implementation of the CLR which can target mobile architectures, but it's still an area of development and not very mature yet.
MonoDroid is the project targetting Android handsets, but it's in a beta stage at the moment.
MonoTouch can target iOS, but it cannot take full advantage of the framework. Apple's licensing prevents virtual machines from running on the iOS, so .NET applications need to be AOT (Ahead-of-time) compiled to run on it. This works, but you won't be able to use parts of the BCL like the reflection API.
There's some early development for mono to support WebOS (Palm) too.

Categories

Resources