Older version of .Net not installed with latest Mono? - c#

I've been working on a .NET 3.5 C# project using Visual Studio Community 2015, but I had always intended to do most of the development on Linux (Ubuntu Gnome 15.04) using Mono and MonoDevelop.
I'm running the latest stable Mono release (4.0.4) and MonoDevelop (5.9.6), which supports .NET 4.5 and can open the VS created solution file without issue.
Now I've been writing C++ apps on Linux for the best part of a decade, but C# and .NET are completely new to me. So I assumed that if I installed a Mono version that supports .NET 4.5, I would get .NET 3.5 as well because the later version is a superset of the older - much like a C++14 compiler supports C++03.
However this doesn't seem to be the case, as MonoDevelop states (under the Target Framework option for each project):
.NET Framework 4.5.1
Mono / .NET 4.5
Mono / .NET 3.5 (Not installed)
So do I have to install a parallel older version of Mono in order to get .NET 3.5 support, or am I just suffering a configuration problem?

No configuration issue, Mono dropped support for the older frameworks in the 4.x release. If you need to compile against the 3.5 assemblies, then yes, you will need a parallel install.
Dropped Support for Old Frameworks
Reference Assemblies
We no longer build the reference assemblies for the .NET 2.0, .NET 3.5
or .NET 4.0 APIs, we now ship binaries of the reference assemblies
(API contracts, without any actual executable code in them).
Mono will now only build the .NET 4.5 assemblies as well as the
mobile-based profiles.
Note: You can still run assemblies compiled for earlier .NET profiles
on Mono, there’s no need to recompile them (they’ll just run on the
.NET 4.5 assemblies instead).

I had a similar issue (project targeting .NET 4.0, but now only 4.5 is available through mono). My workaround was to create a symlink for 4.0:
On my Fedora 32 machine this was done by
cd /usr/lib/mono
sudo ln -s 4.5 4.0
This is supposed to work because there a (almost) no breaking changes between .NET 4 and 4.5 - YMMV

Finally, Got it to work. I'm using Visual Studio for Mac - https://www.visualstudio.com/vs/visual-studio-mac/
Under Preferences->Projects->.Net Runtimes you can change the Default .Net Runtime. It defaults to Mono 4.8.0.
This is located here on a mac : /Library/Frameworks/Mono.framework/Versions/4.8.0
From here you can download older versions of Mono https://download.mono-project.com/archive/
I downloaded 3.12.1 from https://download.mono-project.com/archive/3.12.1/macos-10-x86/
and copied it into the /Library/Frameworks/Mono.framework/Versions/ folder.
Within VisualStudio you can then add the .net framework and set it as default. My project then compiled.

Related

Visual Studio mac 2019 (Community) - PresentationCore - Assembly not found for .Net Framework 4

I'm working on an existing solution at work that was written in C# targeting .NET Framework 4 in Visual Studio 2019 for Windows. I'm attempting to open the project on my MacBook Pro (running Catalina 10.15.6 if that's relevant) in Visual Studio Mac 2019 Community (Version 8.7.7 Build 10) so I can keep working on this remotely.
I'm noticing that a usage of System.Windows.Media isn't being found. My understanding is that this relies on PresentationCore, which I believe is included in .NET Framework 4. Sure enough, in the project's References, PresentationCore has a red "x" next, with alt text telling me "Assembly not found for framework .NET Framework 4".
Is there any way to add this? Is this just something not supported in macOS? I'm happy to provide any additional information.
You are trying to run a WPF application, which targets .Net Framework (4), on MacOS.
MacOS doesn't support WPF, or any version of .Net Framework, as .Net Framework is Windows-dependent1.
Image source: https://visualstudio.microsoft.com/vs/mac/
.Net Core is supported - that's the cross-platform version of .Net, which works on Windows, Mac, and Linux.
You'll need to do a migration to make it work with Core. Of course, this still won't allow you use to run WPF on a Mac, you'd need to use another cross-platform supported UI framework.
1 Of course, Mono is the open-source version of .Net Framework that runs on Mac and Linux, so you can also try that as an option if you're feeling adventurous or can't migrate to Core.
See also: Can you install and run apps built on the .NET framework on a Mac?
Gunr2171 is correct; but you could also look at running a virtual box on your Mac for a windows environment then use VS Code.
For a VM I recommend
https://www.virtualbox.org/wiki/Mac%20OS%20X%20build%20instructions
Then Windows 10 OS:
https://www.microsoft.com/en-ca/software-download/windows10ISO
Just an idea if Mono doesn't work for you.

NET 2.0 project builds from VS2017 but not from the command line

I'm trying to build FluentFTP, which has releases for .NET 2.0, 3.5, 4.0 and .NET Standard. All of the releases build fine within the VS 2017 IDE on Windows 7. However when I try to build using dotnet.exe, it crashes with this error:
"Reference assemblies for framework NETFramework,Version v2.0" were not found...
My build script looks like this:
dotnet --info
dotnet restore -v Minimal
dotnet build -c Release
pause
How do I build this successfully from the console?
It would appear you are missing the .NET 2.0 SDK, here are the links to install it:
x86
https://www.microsoft.com/en-us/download/details.aspx?id=19988
x64
https://www.microsoft.com/en-us/download/details.aspx?id=15354
Per the docs the dotnet build command-line approach is only meant to support .NET Core builds, not .NET Framework builds.
.NET Framework 2.0 isn't supported by any current build system and it also isn't supported by Visual Studio 2017, so I'm surprised it worked correctly. I believe VS2010 was the last version to officially support .NET 2.0 development. .NET Framework builds rely on msbuild (so does dotnet build but with different switches and files).
Visual Studio 2017 Support for .NET Development states that VS2017 supports:
.NET Framework versions 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, and 3.5
.NET Core 2.0, 1.1, and 1.0.
.NET Native
Mono

Build .NET 4.0 and 4.6 Framework app in Jenkins

I have few C# projects which requires .net framework 4.0 msbuild.exe
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" to build the project.
But now i have one c# project which requires .net framework 4.6 msbuild.exe.
So i installed following components:
• Microsoft .NET Framework 4.6
• Microsoft .NET Framework 4.6 Targeting Pack
• Microsoft Build Tools 2015
pointed my msbuild to "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe".
But when i'm installing .net framework 4.6 it upgrades 4.0 so i'm facing issues while building .NET 4.0 Framework apps.
So is it possible to build 4.0 apps with 4.6 msbuild.exe?
The .net framework can only have one installation on each PC for each major version - i.e. 4.*.
The different versions of msbuild are associated with the ms tools version.
The .net 4.6 is a drop in replacement for .net 4.0, so you cannot have both installed, they use the same directory.
You can configure a jenkins slave machine which has the .net 4.0 framework on it, and mark the builds which require .net 4.0 to run on it.
See https://wiki.jenkins-ci.org/display/JENKINS/Step+by+step+guide+to+set+up+master+and+slave+machines

.Net 4.0 targeting on windows 8.x

I'm a bit confused about targeting .net 4.0 app to run on windows 8.x. In my understanding, windows 8.0 comes with 4.5 and windows 8.1 comes with 4.5.1. So my question, if I build a WinForms or WPF client app targeting c#/.net 4.0 (in Visual Studio Project settings) and of course only using .net 4.0 features (i.e, no features from .net 4.5.x), then will this app run fine on windows 8.x without having install .net 4.0 framework (that is, only relying on what comes installed with OS)? Basically, I'm trying to avoid forcing end user to install .net 4.0 framework on their machine before running the app.
Looking at DLLs properties of various Microsoft DLLs (e.g., System) they show same runtime version when targeting either .net 4.0 or .net 4.5.x --> v4.0.30319. So my understanding here is that 4.0 and 4.5.x are targeting same clr runtime version So, my .net 4.0 app should run fine???
From ref here (http://msdn.microsoft.com/en-us/library/bb822049%28v=vs.110%29.aspx), it says .net 4.0 can't even be installed on win8.x.
In my tests, targeting .net 4.0 and running on clean install of win8.1 seems to work fine (without having to install anything else) but looking for advice on gotchas.
Thanks.
Note that the .NET framework is intrinsically backwards compatible - .NET 4.5 will execute .NET 4.0 code just fine. This can be seen even within a solution in that a .NET 4.5/4.5.1 project can reference an older .NET project without incident. This includes .NET 4.0, as well as earlier versions.
In addition to the backwards compatibility, .NET 4.5 does run on the CLR 4.0 - 4.5 is simply a library and compiler expansion.
Possible gotchas
This emphasis on backwards compatibility is why we almost never see functions disappear from the .NET Framework, just get marked [Obsolete]. it's a good idea to check if any functions you use have become Obsolete, though this is rare and such functions usually continue to work as expected.
Windows 8 does NOT like Drive mapping, and will demand that you use UNC paths if you application touches any networks drives.
Windows 8 can be far more aggressive with requiring Admin privileges to run, up to and including needing to explicitly start VS as admin when trying to compile a program which outputs to C:\Program Files\...
Final note: ALWAYS test your application on the targeted platform before releasing to users.
Per this question:
.NET Framework 4.5 was released on 15 August 2012., a set of new or improved features were added into this version. The .NET Framework 4.5 is only supported on Windows Vista or later. The .NET Framework 4.5 uses Common Language Runtime 4.0, with some additional runtime features.
I would say then that by virtue of having .NET 4.5 installed you will also always have .NET 4.0 installed. I don't think this should be an issue then!
From the link you posted:
Each new version of the .NET Framework retains features from the previous versions and adds new features.
Also from that link:
The .NET Framework 4.5 is an in-place update that replaces the .NET Framework 4 on your computer, and similiarly, the .NET Framework 4.5.1 4.5.2, and 4.6 Preview are in-place updates to the .NET Framework 4.5, which means that they use the same runtime version, but the assembly versions are updated and include new types and members.
So, if a system has 4.5, it will be able to run apps targeted for 4.0 as well. The fact that some versions cannot be installed most likely only means that they are already included from the start.

Running Awesomium on .NET 3.5

Does anybody know how I can run Awesomium.NET on .NET 3.5? Seems to only work on 4.0-4.5.1 right now.
According to this question, Awesomium 1.7 should be compatible with 3.5 by adding Awesomium.Mono to the project instead, but it seems like I'm not able to do that. When choosing 3.5 project in Visual Studio the Awesomium.Mono just disappears from the references list.
Well when I started using Awesomium web browser at version 1.7.0 the reference dll are builded using .net 4.0 version. You should try to look for an older version like 1.6.6 or 1.6.5 and check if they are builded using a older .net version. If you target your project to .net 4.0 you should not have any problem because at least windows XP with service pack 3 should have installed .net framework 4.0. But windows XP support has ended.
A quick solution (but not the best) is to target the project to the .net 4.0 and export all dll references to the build path. That should make no problems when deploying the app to your clients machine because the exe will reference to the build path.
Could you give me the reasons of why you are targeting .net 3.5 so I can understand a little more your issue with .net versions and try to think about another solution for you?

Categories

Resources