C
C#13mo ago
Gaweringo

`dotnet build` errors NU1202 but building in IDE works

I have Npgsql.EntityFrameworkCore.PostgreSQL as my package for EF and I tried to run dotnet ef migrations add to create a new migration but it returns with Build failed. Use dotnet build to see the errors.. When I then run dotnet build I get this error:
❯ dotnet build
MSBuild version 17.7.3+8ec440e68 for .NET
Determining projects to restore...
C:\...Web.csproj : error NU1202: Package Microsoft.EntityFrameworkCore.Tools 7.0.13 is not compatible with net70 (.NETFramework,Version=v7.0).
Package Microsoft.EntityFrameworkCore.Tools 7.0.13 supports: net6.0 (.NETCoreApp,Version=v6.0)
C:\...Web.csproj : error NU1202: Package Npgsql.EntityFrameworkCore.PostgreSQL 7.0.11 is not compatible with net70 (.NETFramework,Version=v7.0). Package Npgsql.EntityFrameworkCore.PostgreSQL 7.0.11 supports:
C:\...Web.csproj : error NU1202: - net6.0 (.NETCoreApp,Version=v6.0)
C:\...Web.csproj : error NU1202: - net7.0 (.NETCoreApp,Version=v7.0)
C:\...Web.csproj : error NU1202: Package Microsoft.EntityFrameworkCore.Tools 7.0.13 is not compatible with net70 (.NETFramework, Version=v7.0) / win7-x86. Package Microsoft.EntityFrameworkCore.Tools 7.0.13 supports: net6.0 (.NETCoreApp,Version=v6.0)
C:\...Web.csproj : error NU1202: Package Npgsql.EntityFrameworkCore.PostgreSQL 7.0.11 is not compatible with net70 (.NETFramework,Version=v7.0) / win7-x86. Package Npgsql.EntityFrameworkCore.PostgreSQL 7.0.11 supports:
C:\...Web.csproj : error NU1202: - net6.0 (.NETCoreApp,Version=v6.0)
C:\...Web.csproj : error NU1202: - net7.0 (.NETCoreApp,Version=v7.0)
Failed to restore C:\...Web.csproj (in 157 ms).

Build FAILED.
❯ dotnet build
MSBuild version 17.7.3+8ec440e68 for .NET
Determining projects to restore...
C:\...Web.csproj : error NU1202: Package Microsoft.EntityFrameworkCore.Tools 7.0.13 is not compatible with net70 (.NETFramework,Version=v7.0).
Package Microsoft.EntityFrameworkCore.Tools 7.0.13 supports: net6.0 (.NETCoreApp,Version=v6.0)
C:\...Web.csproj : error NU1202: Package Npgsql.EntityFrameworkCore.PostgreSQL 7.0.11 is not compatible with net70 (.NETFramework,Version=v7.0). Package Npgsql.EntityFrameworkCore.PostgreSQL 7.0.11 supports:
C:\...Web.csproj : error NU1202: - net6.0 (.NETCoreApp,Version=v6.0)
C:\...Web.csproj : error NU1202: - net7.0 (.NETCoreApp,Version=v7.0)
C:\...Web.csproj : error NU1202: Package Microsoft.EntityFrameworkCore.Tools 7.0.13 is not compatible with net70 (.NETFramework, Version=v7.0) / win7-x86. Package Microsoft.EntityFrameworkCore.Tools 7.0.13 supports: net6.0 (.NETCoreApp,Version=v6.0)
C:\...Web.csproj : error NU1202: Package Npgsql.EntityFrameworkCore.PostgreSQL 7.0.11 is not compatible with net70 (.NETFramework,Version=v7.0) / win7-x86. Package Npgsql.EntityFrameworkCore.PostgreSQL 7.0.11 supports:
C:\...Web.csproj : error NU1202: - net6.0 (.NETCoreApp,Version=v6.0)
C:\...Web.csproj : error NU1202: - net7.0 (.NETCoreApp,Version=v7.0)
Failed to restore C:\...Web.csproj (in 157 ms).

Build FAILED.
But when I use the build or run functions in Rider or Visual Studio it builds and runs fine. (Rider also shows errors after running dotnet buildwhich go away after building with rider itself) What I tried: TargetFramework in my .csproj is set to net7.0. I tried net6.0 and I got the same error but with net60.
9 Replies
Angius
Angius13mo ago
Show your csproj?
Gaweringo
GaweringoOP13mo ago
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<SpaRoot>ClientApp\</SpaRoot>
<SpaProxyServerUrl>https://localhost:44442</SpaProxyServerUrl>
<SpaProxyLaunchCommand>npm start</SpaProxyLaunchCommand>
<RootNamespace>PlayCount_Web</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<TargetFramework>net7.0</TargetFramework>
<ApplicationIcon>wwwroot\favicon.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Common" Version="7.0.13" />
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
</ItemGroup>

<!-- Other things about angular -->
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<SpaRoot>ClientApp\</SpaRoot>
<SpaProxyServerUrl>https://localhost:44442</SpaProxyServerUrl>
<SpaProxyLaunchCommand>npm start</SpaProxyLaunchCommand>
<RootNamespace>PlayCount_Web</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<TargetFramework>net7.0</TargetFramework>
<ApplicationIcon>wwwroot\favicon.ico</ApplicationIcon>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Common" Version="7.0.13" />
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="7.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
</ItemGroup>

<!-- Other things about angular -->
Angius
Angius13mo ago
I'm comparing it with my project's .csproj and everything seems to be in order. Except I use 7.0.4 version of NpgSQL and 7.0.10 of the EF tools But I don't thing it should change much
Gaweringo
GaweringoOP13mo ago
Yeah I tried downgrading NpgSql to 7.0.4 but still the same. I also tried creating a new ASP.NET Core with Angular project in VS and tried running dotnet build without doint anything else and I get this error:
C:\Program Files\dotnet\sdk\7.0.402\Microsoft.Common.CurrentVersion.targets(1241,5): error MSB3971: The reference assem
blies for ".NETFramework,Version=v7.0" were not found. You might be using an older .NET SDK to target .NET 5.0 or highe
r. Update Visual Studio and/or your .NET SDK. [C:\...\AngularTestVS\AngularTestVS\AngularTestVS.c
sproj]

Build FAILED.
C:\Program Files\dotnet\sdk\7.0.402\Microsoft.Common.CurrentVersion.targets(1241,5): error MSB3971: The reference assem
blies for ".NETFramework,Version=v7.0" were not found. You might be using an older .NET SDK to target .NET 5.0 or highe
r. Update Visual Studio and/or your .NET SDK. [C:\...\AngularTestVS\AngularTestVS\AngularTestVS.c
sproj]

Build FAILED.
Which says something about .NETFramework which is also in the other error message and confuses me somewhat with .NET Framework being the old pre .NET Core thing. Especially because the first error message is posted has this: not compatible with net70 (.NETFramework,Version=v7.0).... supports: C:\...Web.csproj : error NU1202: - net6.0 (.NETCoreApp,Version=v6.0)
Angius
Angius13mo ago
Huh... Out of curiosity, what does dotnet --list-sdks show?
Gaweringo
GaweringoOP13mo ago
❯ dotnet --list-sdks
7.0.401 [C:\Program Files\dotnet\sdk]
7.0.402 [C:\Program Files\dotnet\sdk]
❯ dotnet --list-sdks
7.0.401 [C:\Program Files\dotnet\sdk]
7.0.402 [C:\Program Files\dotnet\sdk]
Angius
Angius13mo ago
Yeah, I'm out of ideas
Gaweringo
GaweringoOP13mo ago
I finally got it! I had a dotnet 3.0.3 Runtime installed and also the dotnet3-sdk via scoop (for some old thing I tried to build, that I can't even remember right now). I uninstalled that and now it works. I found it as it was in some paths that This SO Answer talked about. Anyways, thanks a lot for your help and time :)
Angius
Angius13mo ago
Seems like it was a very specific and very odd issue lol Glad you got it sorted somehow
Want results from more Discord servers?
Add your server