Long story, summarized...
I started working on a solution creating many projects (like class libraries) for the solution. Then I ended up needing to use a third-party SDK for something I had an expensive license for. Come to find out, that third-party SDK only supported .NET Framework.
Because my solution was based in .NET 5/Core and the SDK in .NET Framework I had a big issue. They can not exist in the same environment and reference each other. So, on to biting the bullet and spending hours converting all my projects to .NET Framework 4.8 while singing a neverending song of curse words...
The Issue
My first class library I'm trying to convert from .NET5 to .NET 4.8 happens to have a Nuget package installed. That Nuget is Newtonsoft.Json Version="12.0.3" (https://www.nuget.org/packages/Newtonsoft.Json).
After changing the framework in the project file, VSCode is telling me the Newtonsoft namespace can not be found. This makes me think that the Nuget I have installed is not compatible with .NET Framework 4.8.
The issue I was running into was the namespace Newtonsoft could not be found after changing the framework from net5.0 to net48.
The issue was OmniSharp that was giving a false positive. I restarted VSCode and the issue went away once VSCode loaded with the new framework being used.
.NET supports cross platform targeting which means you can have your SDK style .NET5 project multi-targets both net5 and net48. In future, if the third-party library targets .NET Core then you can simply change the TargetFrameworks property.
A similar issue has been discussed here https://github.com/dotnet/runtime/discussions/40304 incase if that helps.
Related
I'm writing a C# library targeting .NET Standard 2.0 and .NET Framework 4.6
In other projects (targeting .NET Framework 4.6.1):
When I directly references my library project, the number of produced DLLs are reasonable.
However, when I publish the library to Nuget and install it in other projects, I get an additional 100+ files, and almost all of them are System.*
I wonder if this is due to me misconfigure something when publishing the library to NUGET, or because of something else?
This is expected. Those additional files are required at runtime to make sure your .NET Standard 1.* libraries run on .NET Framework 4.6 and higher.
You can read more about this here.
This question is not a duplicate
I am scripting in Unity using C# with the build in MonoDeveloper-Tool.
When I run the script I got the error message, that the assemblys for framework ".netframework, version=v4.7.1" has not been found. I looked it up on stackoverflow and only found this article:
The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found
So I downloaded this version, but I can't install it, because I already have the latest version installed from .net framework, which is currently .NET Framework 4.7.2
Questions:
Is MonoDeveloper in "Unity 2018.3.12f1 Personal" not supporting this version?
Are there ways to upgrade it to make it work?
Or do I have to remove the .net-version, that I have and get an older one to make it work?
The message you are getting is ususally related to scripting backend setting in PlayerPreferences.
Here's a screenshot from 2017
and from 2019
It defaults to 3.5 for new projects, and you need to manually set it to 4.x, than pretty much all features from 4.7 work fine
Is MonoDeveloper in "Unity 2018.3.12f1 Personal" not supporting this version?
MonoDeveloper supports, but Unity doesn't.
Are there ways to upgrade it to make it work?
Try install .net 4.6 with Visual Studio Installer or upgrade the Unity.
I am pretty new in C# and .NET and I have the following problem.
I created a NUnit (version 3.10.1) project in my solution. The thing that I can't understand is: why the framework version is the 2.1? Is not a very old version? If I try to change it I obtain older version, I am attaching a screenshot:
The strange thing is that the other project into my solution uses the .NET 4.5.2 framnework version.
Why this NUnit project is using an old framework version? there is a way to update it?
What is wrong or what am I missing?
You are targetting .NET Core, which is a completely different framework than the Full .NET Framework.
When you create a new project, you specify the framework to target. You created this one to target .NET Core.
To change your project to target Full framework 4.5.2:
Right click the csproj and select edit <yourprojectname>.csproj
Locate the <TargetFramework> element
Change it from netcoreapp2.1 to net452
Close the csproj file
For more info on .NET Core, you should have a look at the About .NET Core documentation.
.NET Core is an open-source, general-purpose development platform maintained by Microsoft and the .NET community on GitHub. It's cross-platform (supporting Windows, macOS, and Linux) and can be used to build device, cloud, and IoT applications.
And taken from the .NET Core on Wikipedia
I'm trying to wrap my head around the NuGet package system. Recently I released a class library for NuGet, targeting only .NET Framework 4.5.2, but as of demand, I decided to create a new class library targeting .NETStandard 1.4.
Here's where I get lost. Is is possible for me to target multiple frameworks in a single NuGet package, taking this scenario of having two different projects?
Would it make sense for me to remove the .NET Framework 4.5.2 project, and replace it with my .NETStandard 1.4 project? The code is 100% the same.
Any suggestions or best practices to navigate through such a scenario?
If you need to support .NET Framework 4.5.2, you'd need to lower the version of .NET Standard to 1.2 as per compatibility matrix since .NET Standard 1.4 packages can only be used on .NET Framework 4.6.1+.
If this is not possible for you, you can multi-target your project so that the same project is built for a version of .NET Standard and .NET Framework and packages into the same NuGet package. .NET Framework projects referencing that package will prefer the .NET Framework dll over the .NET Standard dll in the same package.
You can do this by changing the .NET Standard project from
<TargetFramework>netstandard1.4</TargetFramework>
to
<TargetFrameworks>net452;netstandard1.4</TargetFrameworks>
By changing the property to TargetFrameworks (plural), the project will now be built twice - once per specified framework.
I really wanted to be a good citizen... copied all my classes to .net standard 1.6 libraries. Just to find out that my test DLL can't use it. I get the following error
Project X targets '.NETStandard,Version=v1.6'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.6.1'.
Of course, when I check .Net Standard (https://learn.microsoft.com/en-us/dotnet/articles/standard/library) it says that with 1.6 it can target 4.6.1.
I tried 4.6.2 without better luck. I installed the .net standard 1.6.1 NuGet package. Anyway, you guys are awesome, I'm sure you'll tell me which stupid mistake I'm making that is preventing me from doing something as basic as running unit tests with a .net standard library.
Thanks
P.S. I did find a work around (kind of) by using a .net core unit test project instead of a .net framework one. It doesn't solve my problem, so I can't mark that as an answer, but at least I can go back to coding...
You need to upgrade to .Net Core SDK 2.x+
Once that is installed restart your machine and you should be able to reference NetStandard 1.6 in .Net Framework 4.6.1+
With .Net Core SDK 1.x you can only reference Net Standard 1.5 in .Net Framework 4.6.2
Best would be to upgrade your Net Standard project to version 2.0 if you can.
In case of errors with similar titles that are targeting different versions of .net framework, this usually means that you need to (install if already not and) change the target of your project to newer/newest version of .net framework to comply with the project that targets newer .net standard.