I recently upgraded my .NET projects from .NET 5.0 to .NET 6.0.
When I attempt to add a migration in Package Manager Console, I get the following error.
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.0.0' (x64) was not found.
- The following frameworks were found:
5.0.12 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
6.0.0 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=win10-x64
I'm confused by this. Why is it looking for version 2.0.0 of Microsoft.NETCore.App? Is that an older version? And why would it be missing now that I've updated my projects to .NET 6.0?
I looked in my project but don't see any reference to this package. Can anyone help me understand what is wrong?
Update
Here is the project file for my main application.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TTRailtraxBusinessLayer\TTRailtraxBusinessLayer.csproj" />
<ProjectReference Include="..\TTRailtraxEntities\TTRailtraxEntities.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Attributes\" />
</ItemGroup>
</Project>
And here is the project file for the library project that contains my entities.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RailtraxCore\RailtraxCore.csproj" />
</ItemGroup>
</Project>
As you can see, there are other library projects being used as well.
CodePudding user response:
Well, Entity Framework's tooling for Powershell has a semantic to pass parameters into EF tools. It passes both the default project and the startup project but for multiple startup projects, it uses the default project as a fallback project. EF tools requires a configured DbContext (associated with a provider and connection string) this is the startup project that consumes the DbContext and configures it. And a migration assembly that locates the migrations and that is usually the project that contains DbContext. So generally when I add migrations with PMC I set the startup project to an application and set the default project in PMC to the DbContext project.
Here is the Powershell module if you want to dig deeper.