-1

I've been trying to create a new project with the layered architecture using layers like: Presentation (Windows Forms Application with .NET Framework), Data (Class Library), Common (Class Library) and Domain (Class Library). When referencing my Presentation layer to the domain layer and common layer, an error like the following occurs that I don't know what it means and I don't know how to fix it: There is no feedback from the visual studio on the error

Also if I want to run or clean the project an error appears that mentions the following:

Project "..\Dominio\Dominio.csproj" has "net6.0" as target. You cannot reference this a project with ".NET Framework,Version=v4.7.2" as the target. Presentation

How can I fix the problem?

I have tried to change the version of .NET in each layer of the project, besides that I have repeated the same procedure several times creating the project from 0.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
  • *"When referencing my Presentation layer to the domain layer"*. It's hard to tell from your wording but you are referencing the library projects in the application project and not the other way around, right? – jmcilhinney Dec 11 '22 at 05:53
  • As error said, your versions are not compatible. You should decide your target platform when you create your project. You can open the project in Visual Studio, then right-click the project in Solution Explorer and select Properties. You can then modify the target platforms one by one in the Application tab, and rebuild. (Or build after clean) If the answers below were helpful to you, please accept them. – Jiale Xue - MSFT Dec 12 '22 at 03:10

2 Answers2

1

.NET Core and .NET Framework projects are not compatible. .NET 5 and later are based on .NET Core. You need to target the same framework in all projects. Either target .NET 6 in all projects or .NET Framework in all projects, or you can target .NET Standard in your library projects and then reference them in .NET Core and .NET Framework projects.

You messed up by not paying attention when creating the projects in the first place. I think you can convert a .NET Framework project to .NET Core, but I'm not sure that it's trivial. When creating projects, pay attention to the project template name - those that target .NET Framework say so in the name - and make sure that all projects that need to work together are compatible.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
0

.Net 6 is based on .Net Core. you cannot refer to a .net framework class library in a .Net 5 or 6 project. So you should create a .Net standard library if you want it to be referred to in both the .Net framework and .net core framework.

Here is the list of compatible versions.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197