Targeting .NET Framework 4.6.1 in Xamarin project - c#

When I create a new Xamarin.Forms project in Visual Studio 2017, in the project properties I can't target any other framework than
.NET standard 1.0
.NET standard 1.1
.NET standard 1.2
.NET standard 1.3
.NET standard 1.4
.NET standard 1.5
.NET standard 1.6
.NET standard 2.0
I'm trying to use a nuget package targeting .NET Framework 4.6.1 and it doesn't load because of that.
I have a warning when i add that package :
The package CHU.Xamarin.Helpers 1.0.0.1 has been restored using '.NETFramework,Version=v4.6.1' instead of target framework of the project '.NETStandard,Version=v2.0'. The package might not be totally compatible with your project.
Is there a way to target .NET Framework 4.6.1 in the project ?
If i add the nuget package anyway, i've got an error saying it is not compatible with monoandroid71 :
The package CHU.Xamarin.Helpers 1.0.0.1 is not compatible with monoandroid71 (MonoAndroid,Version=v7.1). The package CHU.Xamarin.Helpers 1.0.0.1 handles : net (.NETFramework,Version=v0.0)
The error messages are translated from French so might differs from english counterpart

NOTE: None of the following answers "how to target .NET Framework 4.6.1 for a Xamarin.Forms project". If you really, truly, need to know how to do that, and know what you are doing, and why, then search elsewhere - doing so is an advanced topic, and is no longer recommended. For cross-platform projects, stick with a .NET Standard version.
In this case, despite the question title, doing so is not the solution. Keep reading for more details.
I'm trying to use a nuget package targeting .NET Framework 4.6.1 and it doesn't load because of that.
Actually, it does load. It gives you a warning. You can probably ignore that Framework vs Standard warning - I've been ignoring a Framework 4.6.1 vs Standard 2.0 warning for over a year, without problem.
error .. saying it is not compatible with monoandroid71
This is the real problem that is stopping you.
Is there a packages.config file? If so, open it in a text editor, and search for monoandroid71. If present, then yes, this is the problem -
The packages.config mechanism contains an outdated "hint", OR you ARE targeting an older Android version, that is not compatible with the nuget you wish to use - as the message says.
Possible fix:
Target Android 8.0 or higher. In your Android project (e.g. if you named your Xamarin Forms project "App1", look in solution for the project labeled "App1.Android") / Properties / Application / Compile using Android version (Target Framework) / select Oreo or Pie.
Update all nugets to latest.
If packages.config still mentions monoandroid71, then you have outdated "hints".
Different ways to fix outdated hints in project.config. Do ONE of the following:
Rt-click on project.config in Solution pane, select "Migrate to PackageReferences". This newer mechanism doesn't rely on hints.
OR Delete project.config. Add the nugets again.
OR Manually edit project.config. Change all targetframework=monoandroidXX to be the same - whatever the highest number you find in the file. Probably monoandroid81 or monoandroid90.
OR Start all over. Latest VS 2017 version OR VS 2019. Either works fine for this purpose. New project / C# / Mobile App Xamarin Forms. Copy your source files (.cs, .xaml) to the new projects - DON'T use your old .csproj or package.config. The goal is to use all the latest build options, including PackageReferences.

Related

Converting a project from .NET5 to .NET Framework 4.8

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.

How to resolve the error from changing target version of a project in a solution?

In the project I am currently working on, there are several projects in the solution. I had to change the target version of a particular project, which is responsible for handling particular APIs of the project, for installing certain Nuget Packages.
Now there are some .dll not found errors coming when I try to run the project.
How can I resolve this issue?
My project is based on .net framework and I am using Visual Studio 2017.
My actual Target version was .NET Framwork 4.5.1.
I had to change it to 4.6.1 since the package I was trying to install IBM.Watson.NaturalLanguageUnderstanding.v1 -Version 4.2.1 package.
Errors are like this:
Metadata file 'location\ProjectName.dll' could not be found.
My actual Target version was .NET Framwork 4.5.1. I had to change it
to 4.6.1 since the package I was trying to install
IBM.Watson.NaturalLanguageUnderstanding.v1 -Version 4.2.1 package.
I recreated the problem by attempting to install the nuget on a new console app targeting .netframework 4.6.1 and it failed
This is where problem lies, IBM Watson NaturalLanguageUnderstanding is compatible with .NETStandard 2.0 Specification which means you would need to target 4.6.1 (*2) ideally, but here is the catch (as explained here MSDN)
2 ways to solve this
Target .NetFramework 4.7.1 as recommended by the MSDN above OR
If you want to use 4.6.1 then you would need to add this to your .CSPROJ file
<PropertyGroup>
.
.
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
To resolve the issues, change the target frameworks of the projects that are dependent on the project for which the target framework was changed. In most cases, there won't be much problem since Microsoft gives backward compatibility. There might be some problems with third-party NuGet packages. Also, some reference errors might come when deployed.

Roslyn for .Net 4.7.2 [duplicate]

This question already has answers here:
Installing a .NetStandard 2.0 Nuget package into a VS2015 Net 4.6.1 project
(2 answers)
Closed 3 years ago.
I am so confused.. I am trying to install a nuget package that has a dependency on .NetStandard v2.0, after reading this post about it, it made sense to me that I could run any library that is dependent on .NetStandard 2.0 with .Net 4.7.2. Unfortunately, while trying to install a nuget package, it fails, saying it is not compatible with .net 4.7.2.
I am mainly trying to add the new Roslyn libraries Microsft.CodeAnalysis and if you look at the dependencies it says it supports .Net 4.7.2, the issue seems to stem from another dll its dependent on Microsoft.CodeAnalysis.CSharp.Workspaces, as that says it only has a dependency on .NetStandard 2.0. (but really .Net 4.7.2 can run .NetStandard 2.0)
Does anyone know if this is possible or will I be needing to move to .net core framework to be able to support a project like this?
Really it should say it only has a dependency on .NetStandard 2.0 but be able to get installed onto a target framework with 4.7.2 or .Net Core
Edit:
Using Visual Studio 2015 and C#6.
Its a rehosted windows workflow designer application (working on c# compilation/intellisense for inputs to the designer)
Thanks to #IanKemp for finding an answer that helped me, I will flag this post as a duplicate but I wanted to first post a step-by-step fix for future developers that may come across this.
So I downloaded the latest Nuget version (VS 2015 VSIX - latest v3.6.0) here
Then I tried to update to the latest Roslyn package via NuGet package mananger and got this error message:
The message points you to this link, that will download the .Net Standard Build Support extension: https://aka.ms/netstandard-build-support-netfx
I then tried to update to the latest Roslyn package and it all worked!!
Happy coding all.

Error: The current .NET SDK does not support targeting .NET Standard 2.0

Getting annoying build errors since upgrading to VS2017 (v15.18.6) and dot net core 2.1.
I previously was able to build the .sln from https://github.com/MiniProfiler/dotnet.
I'm new to the whole .net standard/core stuff (frankly find MS approach to this rather confusing and annoying!).
Anyway since the upgrade to the new VS2017 build and 2.1, I get the following 2 errors:
Severity Code Description Project File Line Suppression State
Error The current .NET SDK does not support targeting .NET Standard 2.0. Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0. MiniProfiler.Shared C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets 126
Error NETSDK1050 The version of Microsoft.NET.Sdk used by this project is insufficient to support references to libraries targeting .NET Standard 1.5 or higher. Please install version 2.0 or higher of the .NET Core SDK. MiniProfiler.Shared C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\Microsoft.NET.Build.Extensions.NETFramework.targets 67
Any ideas ?
I have searched online and seem various similar issues but I don't really understand the underlying issue.
it seems you're using core and not targeting it. and it seems somehow you've brought standard and core into your app and thats causing a conflict. go through youre dependencies and references and make sure all the .NET options are set to the same either core or standard. then once youve chosen youre version, make sure to set the target to match it. standard is slightly more powerful at the moment, but its about to be depricated, so if you can switch to core and still have the functionality you need i reccomend doing do as this will increase the longevity of your project. plus linux and mac options.

Change the .net framework with visual studios 2013 and the xamarin plug in

I am trying to change the .net framework for a android c# app in visual studios 2013. I tried to create a new project with .net framework 4.0 but I still get an error saying that my application is targeting the 4.5 framework. Does anyone know how to force this? The reason I am doing this is that I have a nuget package that uses the 4.0 framework, however if there is a way to get that nuget package to use the 4.5 framework that is an equally valid solution.
You cannot change the .net framework for an Android app. It will always be targeting MonoAndroid.
You cannot use a NuGet package that only assemblies for the .NET framework since they may use parts of the Xamarin Android API that is not supported.
So you are left with finding another NuGet package that supports Android projects or re-compiling the source code in an Android library project so it targets MonoAndroid, which may or may not work depending on what the source code does.

Categories

Resources