Sdk: Project '..' targets 'net5.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v5.0'

Created on 25 Mar 2020  路  24Comments  路  Source: dotnet/sdk

While trying to reference a NET5.0 class library project from a NET5.0 WinForm project I get the error stated in the title:

Project 'classlib.csproj' targets 'net5.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v5.0'

All 24 comments

Preview 1 doesn't have support for the new TFMs yet.

It looks like you don't have the latest bits. Can you make sure you're using Preview2 or later SDK and VS 16.6 preview 2 as well?

Please reopen if you still face an issue using latest.

@ericstj I am using Preview 3 and I am getting the same error. Trying to add a net5.0 class library to a webapi 5.0 project.

cc @rrelyea @dsplaisted

@ansarizafar This is an update to NuGet, so if you are using Visual Studio or full Framework MSBuild, you will need to make sure you have the right VS version. Also if you are using nuget.exe to restore you will need an update to that.

What version of VS are you using? How are you building / restoring when you get this error?

@zkat

@dsplaisted I am using VS code (Code-server) in browser with C# extension. The error appears when I load the project and I can see the details in output panel. I am not using nuget.exe

@dsplaisted I transferred this over to dotnet/sdk.

@ansarizafar Likely you need to update the version of the .NET SDK you are using. @DustinCampbell

@ansarizafar for vscode I changed the version in my .csproj file from <TargetFramework>net5.0</TargetFramework> to <TargetFramework>net4.8</TargetFramework>
then I closed and reopened vscode on my project folder and the error was no more.

assuming that you are also using the extension C# for Visual Studio Code (powered by OmniSharp) and that 5.0 is not a must

I'm getting this same error. These are the versions I'm using:

$ dotnet nuget
NuGet Command Line 5.8.0.4
$ dotnet build
Microsoft (R) Build Engine version 16.8.0-preview-20451-02+51a1071f8 for .NET

and

$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.100-rc.1.20454.5
 Commit:    53a032d031

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.15
 OS Platform: Darwin
 RID:         osx.10.15-x64
 Base Path:   /Users/mj/Documents/develop/runtime/.dotnet/sdk/5.0.100-rc.1.20454.5/

Host (useful for support):
  Version: 5.0.0-rc.1.20451.14
  Commit:  38017c3935

.NET SDKs installed:
  5.0.100-rc.1.20454.5 [/Users/mj/Documents/develop/runtime/.dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.0-rc.1.20451.17 [/Users/mj/Documents/develop/runtime/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.0-rc.1.20451.14 [/Users/mj/Documents/develop/runtime/.dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

cc @nkolev92

We did some fixes in https://github.com/NuGet/NuGet.Client/commit/935b1d2f5bef8d0d78a737190846b72f0bae30e9 and https://github.com/dotnet/msbuild/commit/79ab985eb5b6552d96d237d4179237b4b850ca64.

I'm not sure which was the first version of the SDK that had both these fixes though.

I experienced the same problem (now solved) when I tried to upgrade a solution (everything set to netcoreapp3.1) to everything set to net5.0.
In my case, I had a gRPC service, with a reference to a WPF project. Everything worked nicely...until I tried to upgrade the solution:
Error NU1201 Project OneClick.Document is not compatible with net5.0.
The message is very misleading...in fact, you can have everything set to net5.0. It was a bit tricky in my case, since I had a gRPC service who had a reference on a WPF project. The solution is somewhat weird:

Project Sdk="Microsoft.NET.Sdk.Web"
PropertyGroup
TargetFramework>net5.0-windows PropertyGroup

[......]

On the gRPC service, since you're referencing a WPF project, you need to set

<TargetFramework>net5.0-windows</TargetFramework>

instead of
net5.0
Nonetheless, at the same time, the Project Sdk must be Microsoft.NET.Sdk.Web.

While trying to understand this problem I created a new gRPC service (net5.0 by default), then I created a new WPF project (netcoreapp3.1 by default) and when I tried to reference it, I got the right suggestion; you don't get it if the gRPC service TargetFramework is set to netcoreapp3.1, which was my situation originally.
Now I have everything set to net5.0 (or net5.0-windows) and it works like a charm.

Me again...
I do have a minor side effect: the publish would fail:
C:\Program Filesdotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): Error NETSDK1005: Assets file 'S:\Codice\2021\InformedConsentServer\obj\project.assets.json' doesn't have a target for 'net5.0'. Ensure that restore has run and that you have included 'net5.0' in the TargetFrameworks for your project.

I can build the solution and manually copy the files, though.
bye

Is there a reason that this is still a problem?

Is there a reason that this is still a problem?

Hello eviathan,
if you're referring to the publish fail, then yes, to my knowledge it is still an issue.
If you're referring to the general issue of this topic, I was able to solve it, as I explained in the first of my 2 messages. I do not know if my case is a peculiar lucky case or if that is the solution to the issue...

@robertodalmonte Can you share a binlog of the failed publish operation? Thanks.

binlog.zip
Hopefully, this is what you're looking for...

This is from Visual Studio
14/12/2020 09:29:43
System.AggregateException: One or more errors occurred. ---> Microsoft.WebTools.Shared.Exceptions.WebToolsException: Build failed. Check the Output window for more details.
--- End of inner exception stack trace ---
---> (Inner Exception #0) Microsoft.WebTools.Shared.Exceptions.WebToolsException: Build failed. Check the Output window for more details.<---

Microsoft.WebTools.Shared.Exceptions.WebToolsException: Build failed. Check the Output window for more details.

===================

Does it fail if you publish from the command line, or just from within Visual Studio?

I use Visual Studio 2019 Community Edition, and it fails.
Just now I tried in Visual Studio Code, from terminal:
dotnet publish --configuration Release
and it worked nicely
Screenshot (29)

@vijayrkn Could you look at @robertodalmonte's issue here with publish from VS? It looks like it's not restoring for the right RuntimeIdentifier or something.

Updating Visual Studio 2019 from Visual Studio Installer solve my similar error.

Moving from 16.7.7 to 16.8.3 solved this error for me.

Was this page helpful?
0 / 5 - 0 ratings