How can I change my sdk .net version .net5 to .net6 - c#

I need your help. I'm working in a .net5 project and I created a xUnit project but I created with .net6 and it is conflicting.
I tryied to change target frameworking in file .csproj but I beliave that it more things.
Thanks very much.

To change the .net version of your project, right click on your xUnit project, and go to Properties. After that,change the Target Framework version

Related

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.

Version Conflict detected for Microsoft.EntityFrameworkCore.Install

I am getting the following error when adding an asp.net core api to an existing project I am working on.
"Version Conflict detected for Microsoft.EntityFrameworkCore.Install/reference Microsoft.EntityFrameworkCore 2.2.1 directly to project to resolve this issue"
I tried to add the Nuget package but get further version conflicts across a number of different packages and the process always fails.
At first I thought this may be an issue with my project so I started a new solution from scratch and managed to replicate the issue with a few simple steps.
Create a new solution (EFDemo)
Add a new .net Core class library to the solution called EFDemo.BL
Add the following Nuget packages to project EFDemo.BL (as I'm using an existing database for my new project)
Microsoft.EntityFrameworkCore.SqlServer (v2.2.1)
Microsoft.EntityFraneworkCore.Tools (v2.2.1)
Add a new .net core web application called EFDemo.Api and select the API project template.
Add a reference from EFDemo.BL to EFDemo.Api.
Build and see the failure.
I have reviewed the following post but its solution does not work for me as I have no reference to "Microsoft.EntityFrameworkCore" in any of my csproj files.
Version conflict detected for NuGet packages.
I have also reinstalled .net SDK, rebooted a million times and still can't understand what the issue is.
I have encountered the same error recently.
What I have done to sort this out:
Installed .Net Core 2.2 SDK
Then in my project I have changed in all .csproj files:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
whereas before it was:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
This helped straight away and the error dissapeared.
The answer to this is quite difficult to catalog because I made many changes while trying to figure this out.
In the end, I believe the following steps fixed my issue:
Upgrade VS to the latest version (v15.9.3)
Uninstall both .Net Core 2.1 and 2.2 SDKs (my project was using 2.1 at the time)
Install .Net Core 2.2 SDK
Convert all projects in my solution to use .Net Core 2.2 (A pain. I wish there was a Retarget All function!)
Reboot, Clean, Build and it works. Phew.
Now to do some work instead of fighting with my tools!
For me, it helped this article, it was a very simple change on the configuration, which I forgot to change:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
https://dotnetcoretutorials.com/2018/11/18/how-to-target-net-core-2-2/
I am not sure what package you have installed in your project.
But now days visual studio add just one nuget packages which includes all of required package for asp.net core application.
Try installing this package and remove all other package and see it that works for you.
Microsoft.AspNetCore.All
This way you will not have version conflict at least within Microsoft packages. You can then verify other external package that you might have installed which is causing problem.
I fixed this just installing .NET Core 2.2 and changing TargetFramework tag to netcoreapp2.
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
I had followed the steps to solve my problem
Download and install the latest framework (dotnet core 2.2 in my case)
Set the project target framework to highest (dotnet core 2.2 in my case) from project properties
Clean solution
4 Rebuild solution
Update any version disputes (optional)
Rebuild and save.
Hope this helps.

Why creating an NUnit project into my solution it use an old version of .NET framework (2.1)?

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

Visual Studio 2017 error: Cannot find project info for “” This can indicate a missing project reference - with Console App .NET Core 2.1

VS 15.7.5
I have a .NET Standard 2.0 class library:
It exists in its own solution but I have now added it to a different solution so that I can use it with my .NET Core 2.1 Console test runner:
However as soon as I do this I get the error. If I remove the console application then everything compiles without error.
So what am I missing here? Why can a .NET Core 2.1 Console application not find my .NET Standard 2.0 class library?
I just tried to replicate what you did and it worked for me !
My .net 2 standard
That has only one class
public class School
{
public string Name => "Mango Hill";
}
And my .net core 2.1 project
that calls the class from the library
you can see the output.
So I suggest you check the common project to see if it references any full library and then try to isolate the references.
The issue here is that for whatever reason .NET Core Console apps will fail with the error I received if the following are true:
You create the standard project within a folder under the original solution that contains it. So say you have a solution called slnStandard in the path D:\Rubbish\slnStandard.
You then add a new standard class library project Standard.Project.cproj in the path:
a) D:\Rubbish\slnStandard\Standard.Project <== Will Compile in slnStandard
b) D:\Rubbish\slnStandard\SubFolder\Standard.Project <== Will Compile in slnStandard
Create second solution slnSecond and add a solution folder called MySolutionFolder. Add Standard.Project.cproj from 1 above (both versions). slnSecond will compile
Add a MSTest .NET Core Console application to slnSecond. Then "Add Reference" > Project using what has been added in 2.
If the reference is 1b) it will NOT COMPILE. So basically you need to keep the folder structure flat. Hopefully this will be fixed moving forward.
Just try running "build" or "restore" command using Dotnet CLI 2.1 version. from command window
c:\path> dotnet restore [.net core 2.1 console].csproj
this may be required once if you switch TargetFramework using visual studio.
either from .net core 2.0 to 2.1 or vice versa
If you could build the console project from dotnet CLI command "build". and you are getting this error only in visual studio.
Please try to create solution using dotnet "sln" and "add" command to refer the projects.
This happened to me when the path was cloned from git with spaces "%20". After I removed the spaces, it built without issues in Visual Studio 2017. Interestingly, I had the same issue in JetBrains Ryder, but not the command line (dotnet build).

How do I target .NET Standard 2.0 in a freshly created .NET Core 2.0 web app?

I've just created a fresh project using dotnet new web. My Google-foo may be failing me, but I didn't find anything relating to my answer (please link to another SO answer, or relevant documentation if I've missed something obvious).
If I want to ensure this new project is .NET Standard 2.0 compliant, what do I now do?
It is not inherently possible to run a netstandard project as an executable. Since netstandard was designed to be used for libraries.
In order to develop your web application entirely in netstandard2.0, you would have to create a separate project that targets either .NET Core or .NET Framework to execute your library that contains your web app (developed using .NET Standard).
1. Executable Project (ex: console app)
-- Target Framework: netcoreapp2.0 / net462
2. Web Application Project (library)
-- Target Framework: netstandard2.0
You can use the following steps to change the target framework of your project.
Step 1. Target the desired framework
Right-click on your project and select Edit *****.csproj
In the .csproj file, you need to replace the target framework to the .NET Framework.
Example .csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web"> //<-- note the .Web for the web template
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
For a list of the Target Framework Moniker (TFM) (ie, net47, netstandard2.0, netcoreapp2.0, etc.*) you can check this link out:
https://learn.microsoft.com/en-us/dotnet/standard/frameworks
Step 2. Run dotnet restore
Go to your output window and run dotnet restore.
Note: Sometimes Visual Studio may misbehave (depending on which update you have installed), so you may have to close and re-open your Visual Studio. Otherwise, sometimes a clean/re-build may do the trick.
Targeting both frameworks
You can pick one or the other, or even target both frameworks.
<TargetFrameworks>netcoreapp2.0; net47</TargetFrameworks> //<-- note the plural form!
NET Standard is for class libraries. Applications must target netcoreapp* where * is a version number. The following shows the compatibility matrix: https://learn.microsoft.com/en-us/dotnet/standard/net-standard
For example, .NET Core 2 can consume .NET Standard version 2 and below.

Categories

Resources