dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.78k stars 3.18k forks source link

Bundle-Migration "failed to restore project" or "it was not possible to find any compatible framework version" #27317

Open StephanBis opened 2 years ago

StephanBis commented 2 years ago

We're trying to get the Bundle-Migration to work so we can integrate migrations in our CI/CD pipelines. We are however facing some issues.

When using the dotnet CLI, we're getting 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:
      3.1.22 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      6.0.1 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

When using the Package Manager Console Bundle-Migration command

Failed to restore xxx.csproj (in 2,51 sec).
Failed to restore xxx.csproj (in 2,51 sec).
Restored xxx.csproj (in 2,51 sec).
Restored xxx.csproj (in 2,51 sec).
Restored xxx.csproj (in 2,51 sec).
Restored C:\Users\xxx\AppData\Local\Temp\zbp3cxwh.dds\efbundle.csproj (in 2,69 sec).
Microsoft.EntityFrameworkCore.Tools.CommandException: Build failed. Use --verbose to see errors.
   at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsBundleCommand.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0(String[] args)
   at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)

We do not understand why the dotnet CLI is complaining about .NET Core 2.0.0 as we are not referencing any packages that require this framework. On the other hand our projects restore and build just fine, no issues. So we also do not quite understand why ef-tools cannot restore some projects.

Versions:

ajcvickers commented 2 years ago

/cc @bricelam

ajcvickers commented 2 years ago

Possible duplicate of #16882.

@StephanBis Can you post your csproj?

krsnider commented 2 years ago

Hello! Sorry to hijack, but my team has been running into this problem this week. This is our csproj.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <RootNamespace>Redacted.Project.Data</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="5.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />
    <PackageReference Include="Microsoft.Identity.Client" Version="4.29.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />
  </ItemGroup>

</Project>

We have tried removing both the DotNetCliToolReference Item Group and the Microsoft.EntityFrameworkCore.Tools.DotNet PackageReference along with many other random attempts.

Note: Our startup project is a separate project, this project has a single DbContext which is the only DbContext in the solution

ajcvickers commented 2 years ago

@krsnider This:

<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />

is an extremely old and obsolete package. It was replaced by the dotnet-ef before EF Core 2.1 shipped, but neither are intended to be referenced using PackageReference from a csproj.

Note for triage: the package is already listed as obsolete here: https://docs.microsoft.com/en-us/ef/core/what-is-new/nuget-packages

StephanBis commented 2 years ago

Sorry for the late reaction.

Our database .csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
  </ItemGroup>
</Project>

Our startup project

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
    <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.5.1" />
    <PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="10.0.1" />
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.20.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
  </ItemGroup>
</Project>

As you can see we are not using the above mentioned Microsoft.EntityFrameworkCore.Tools.DotNet.

AndriySvyryd commented 2 years ago

@bricelam cc

bricelam commented 2 years ago

Related to https://github.com/dotnet/efcore/issues/27385#issuecomment-1035511704?

StephanBis commented 2 years ago

Any update on this? I see that this is added to the 7.0.0 milestone.

ajcvickers commented 2 years ago

@StephanBis We don't yet understand what is going on here. The plan is to investigate and hopefully fix in 7.0 if we find the root cause. The workaround for now is to install .NET 2.x where needed.

bricelam commented 2 years ago

This may have been fixed by PR #27671