XF requires .NETFramework >= v4.6.1. You have 'v4.5.1' - xamarin.forms

When compile or debug a package project (.wapproj) with inside a Xamarin Form UWP application, recevive this error:
XF requires .NETFramework >= v4.6.1. You have 'v4.5.1'

Add this on .wapproj
<Project ...>
...
<PropertyGroup>
<XFDisableFrameworkVersionValidation>True</XFDisableFrameworkVersionValidation>
</PropertyGroup>
...
</Project>

Last VS 2019 update 16.9.2 resolve this issue for me.
Try it.
Carbonete

Related

Error running a brand new Blazor App with .NET Core 6.0

In Visual Studio 2022, I create a new Blazor WebAssembly App. VS does its thing and scaffolds the project with a .sln file. I hit the Run button and I'm met with error CS0246: The type or namespace name 'MyBlazorApp' could not be found (are you missing a using directive or an assembly reference?)
Interestingly, this doesn't show up in my Error List window, just as a build output. Googling is only showing me some people having a similar problem with older versions of .NET Core, and the solution in most cases is to update VS2019. Is it possible this is the same bug cropping up again in a new version of VS?
This is not the answer per se, but as usual I need more than the comment space available:
Check what version of dotnet you are running run : dotnet --version.
I have:
PS C:\Users\shaun\Documents\GitHub\Blazr\Blazr.Demo Sites\MyBlazorApp> dotnet --version
6.0.101
PS C:\User
Downgrade the packages in the project file and check whether the project builds and runs.
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.1" PrivateAssets="all" />
</ItemGroup>
</Project>

How to show message box on .net core Console application?

I'm developing .net core console application. I want to alert to user when want to exit application. Like below;
MessageBox.Show("Contiue or not", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.None, MessageBoxDefaultButton.Button1) == DialogResult.No)
Application.Exit();
But I can't add System.Windows.Forms referance to the my project. I'm getting this error.
Error CS0234 The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
Is that possible to show Message Box on .net core Console Application?
In order to use Windows Forms you need to modify .csproj:
set UseWindowsForms to true
append -windows to TargetFramework (e.g. net6.0-windows)
ConsoleApp.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>
Program.cs:
System.Console.WriteLine("Hello, Console!");
System.Windows.Forms.MessageBox.Show("Hello, Popup!");
Result:
Notes:
I checked this solution on .NET Core 3.1, .NET 5 and .NET 6 on Windows x64.
If you don't want console window to be shown, set OutputType in .csproj to WinExe instead of Exe.
Windows Forms works only on Windows, so as this solution.
On .NET Core 3.1 there is no requirement to change target framework to Windows, however it is still impossible to publish executable for Linux OS.
If you need cross-platform solution that shows popups on Windows and only use console on Linux – you can create custom build configuration and use preprocessor directives as in the example below.
Cross-platform ConsoleApp.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Configurations>Debug;Release;WindowsDebug;WindowsRelease</Configurations>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'WindowsDebug' Or '$(Configuration)' == 'WindowsRelease'">
<DefineConstants>WindowsRuntime</DefineConstants>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>
Cross-platform Program.cs
System.Console.WriteLine("Hello, Console!");
#if WindowsRuntime
System.Windows.Forms.MessageBox.Show("Hello, Popup!");
#endif
Some console apps need this line added to the project as well...
<DisableWinExeOutputInference>true</DisableWinExeOutputInference>
Adding this to the example in Daniil's post would give you this...
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<!--Insert DisableWinExeOutputInference here -->
<DisableWinExeOutputInference>true</DisableWinExeOutputInference>
</PropertyGroup>
</Project>

SGEN error on Build of Release version of mixed ASP.Net and .Net Standard 2.0 projects Solution

I am working on a Visual Studio 2017 Solution that contains 3 projects:
Two Class Libraries in .Net Standard 2.0 (Any CPU)
One ASP.Net in .Net Framework 4.6.1 (Any CPU)
If I Build All in Debug (Any CPU), all runs fine.
But if I Build All in Release (Any CPU), then this error shows in the Output Window:
3>SGEN : error : An attempt was made to load an assembly with an incorrect format: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\ref\netfx.force.conflicts.dll.
How to solve it?
The error stems from confusion between NETStandard and NuGet libraries when resolving dlls. Put this into your failing project's .csproj file (Unload project, Edit .csproj file):
<Target Name="ReplaceNetFxNetStandardRefWithLib" AfterTargets="ImplicitlyExpandNETStandardFacades">
<ItemGroup>
<Reference Remove="#(_NETStandardLibraryNETFrameworkReference)" Condition="'%(FileName)' != 'netfx.force.conflicts'" />
<Reference Remove="#(_NETStandardLibraryNETFrameworkReference)" Condition="'%(FileName)' != 'System.Configuration.ConfigurationManager'" />
<Reference Include="#(_NETStandardLibraryNETFrameworkLib)">
<Private>true</Private>
</Reference>
</ItemGroup>
</Target>
<Target Name="RemoveNetFxForceConflicts" AfterTargets="ResolveAssemblyReferences">
<ItemGroup>
<ReferencePath Remove="#(ReferencePath)" Condition="'%(FileName)' == 'netfx.force.conflicts'" />
<ReferencePath Remove="#(ReferencePath)" Condition="'%(FileName)' == 'System.Configuration.ConfigurationManager'" />
</ItemGroup>
</Target>
In my case, this error was reported due to incorrect package installed in the project. Though you uninstall the incorrect package installed it was still reporting error, the solution will be
Ensure to uninstall the package with the option "Force uninstall even if there are dependencies on it"
Even after following step 1 if you still encounter the same sgent error, then expand "References" node in solution explorer, remove the unwanted dlls that might have been installed as part of installing the incorrect package.

Convert .Net Core to .Net Framework

I have a .Net Core project web project, and for various reasons want to convert it to a .Net Framework project.
Is there an easy way to do this, or do I have to start again and import the code from the previous projects
I have loaded core project to the VS 2017 RC Community and open *.csproj in text editor.
Just delete teg
<RuntimeFrameworkVersion>
and replace
<TargetFramework>netcoreapp1.1</TargetFramework>
to
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
And after all in project properties set to any another framework and reset back (VS reload and repair *.csproj file).
This worked for me in VS2017:
Start with .net core web project template.
Edit *.csproj so it looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.RazorPages" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
</ItemGroup>
</Project>
Save and close.
Try running project.
The PackReferences is just the NuGet files, and you can add them through the GUI if the versions are different from mine above.
There's lots of similar answers here, but I didn't see one that was quite what I ended up doing, so I'd like to leave this here just in case someone else is in the same shoes.
Just to be clear, my project was a console program. So, if you're trying to use this answer for something else, your mileage may vary.
In your .csproj file, inside of the <PropertyGroup></PropertyGroup> tag, modify <TargetFramework> to reflect the following:
<TargetFramework>net461</TargetFramework>
Now, in this example, I was using v4.6.1. I can only assume that you'll plug in your version behind the word "net", without the periods. Good luck!
None of the answers here worked for me. In .Net Core 2 the project.json file no longer exists. However, I did solve this problem using the following steps.
1) I removed all nuget packages from my existing project.
2) I created a separate .net core web app project, targeting .net 4.61. This was to get the default nuget packages.
3) I edited the temporary project's .csproj file, copied all the PackageReference nodes inside ItemGroup, and pasted them into my existing projects .csproj file.
4) Edited the TargetFramework node (inside PropertyGroup) from "netstandard2" to "net461"
I had a few package changes to track down and resolve, but otherwise I was able to run.
In my version of Visual Studio 2017 (15.6.2) after 'Unloading the Project', right-clicking and selecting 'Edit <your project file>, I had to:
Add the node:
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
Delete the nodes:
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.16299.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
There are several steps that you need to do, in order to achieve this.
Firstly right click on the .csproj file and add the following
<TargetFrameworks>netstandard2.0;netcoreapp2.0;net35;</TargetFrameworks>
<RuntimeIdentifiers>win7-x86;win7-x64</RuntimeIdentifiers> <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
Once you have made these changes reload the project and build it.
This will generate the .dll files and Nuget package for this
build in the Debug/Release folder of the project.
Add these .dll to the nuget and access these projects from
nuget.
Try the above steps. This should work.
My .net standard project is relatively simple with few Nuget packages. I just changed
<TargetFramework>netstandard2.0</TargetFramework>
TO
<TargetFramework>**net461**</TargetFramework> under PropertyGroup section of .csproj file and this did the job for me.. Thanks to Brandon Barkley for your answer in the comments.
add below in csproj
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net471</TargetFrameworks>
</PropertyGroup>
I had only a handful of source files. For me it worked best by
Closing Visual Studio 2022
Renaming away the solution folder
Creating a new Visual Studio solution of type "WPF App (.NET Framework)" with the original folder name and same project name
Copying all *.xaml. *.xaml.cs and *.cs from the old project to the new, not touching *.sln, *.csproj and *.config.
Project->Add Existing Item… and adding the copied items
Adding all the special references.
That rebuilt all without a complaint.

Newtonsoft.Json causes failure of Visual Studio 2015 Code Analysis

Newtonsoft.Json version in NuGet (version 7.0.1) gives the below error message when running code analysis.
CA0001 : Could not resolve reference to mscorlib, Version=2.0.5.0, ...
The error occurs in portable class library that targets .Net 4.5, Windows 8 & ASP.NET Core 5.0
The error does not occur if the portable class library targets .Net 4.6, Windows Universal 10 & ASP.NET Core 5.0
I took Newtonsoft.Json source code and compiled to portable class library targeting .Net 4.5, Windows 8 & ASP.NET Core 5.0. Then I referred to the assembly I compiled instead of the NuGet package. The code analysis problem does not happen in this scenario.
Note that I use Visual Studio 2105 running on Windows 10. Targeting .Net 4.6 is not an option for me due to other dependencies.
Please let me know if there is a good way to make the NuGet package work for the particular PCL target I need and code analysis.
You can avoid the error by adding a CodeAnalysisAdditionalOptions /assemblyCompareMode:None to your .csproj file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
....
<CodeAnalysisAdditionalOptions>/assemblyCompareMode:None</CodeAnalysisAdditionalOptions>
....
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
....
<CodeAnalysisAdditionalOptions>/assemblyCompareMode:None</CodeAnalysisAdditionalOptions>
....
</PropertyGroup>
....
</Project>
It seems the bug was fixed in Version 9.0.1.

Resources