Ядро 3.1: Не удается запустить миграции dotnet ef в проекте .DLL (фреймворк не найден)

#.net-core #entity-framework-migrations #dotnet-tool

#.net-ядро #entity-framework-миграции #dotnet-инструмент

Вопрос:

Я столкнулся с проблемой после обновления проекта до ядра 3.1.

У меня настроено ядро EF в библиотеке классов (DLL). Когда я запускаю

 dotnet ef migrations add Init --context TransferDbContext --verbose
  

Я получаю сообщение об ошибке:

 Build started...
Build succeeded.
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '3.1' was not found.
  - The following frameworks were found:
      3.1.7 at [C:Program FilesdotnetsharedMicrosoft.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.Appamp;framework_version=3.1amp;arch=x64amp;rid=win10-x64  
  

Сбой вызова:

 dotnet exec 
    --depsfile C:tfsDigitalEksamenIntegrationDigitalEksamenIntegrationBusinessbinDebugnetcoreapp3.1win-x64DigitalEksamenIntegrationBusiness.deps.json 
    --additionalprobingpath C:Usersdalby.nugetpackages --additionalprobingpath "C:Program FilesdotnetsdkNuGetFallbackFolder" 
    --runtimeconfig C:tfsDigitalEksamenIntegrationDigitalEksamenIntegrationBusinessbinDebugnetcoreapp3.1win-x64DigitalEksamenIntegrationBusiness.runtimeconfig.json 
    C:Usersdalby.dotnettools.storedotnet-ef3.1.0dotnet-ef3.1.0toolsnetcoreapp3.1anytoolsnetcoreapp2.0anyef.dll migrations 
    add Init --context TransferDbContext 
    --assembly C:tfsDigitalEksamenIntegrationDigitalEksamenIntegrationBusinessbinDebugnetcoreapp3.1win-x64DigitalEksamenIntegrationBusiness.dll 
    --startup-assembly C:tfsDigitalEksamenIntegrationDigitalEksamenIntegrationBusinessbinDebugnetcoreapp3.1win-x64DigitalEksamenIntegrationBusiness.dll 
    --project-dir C:tfsDigitalEksamenIntegrationDigitalEksamenIntegrationBusiness 
    --language C# 
    --working-dir C:tfsDigitalEksamenIntegrationDigitalEksamenIntegrationBusiness 
    --verbose 
    --root-namespace DigitalEksamenIntegration.Business
  

Мой

 dotnet --info
  

Перечислены следующие:

 .NET Core SDK (reflecting any global.json):
 Version:   3.1.401
 Commit:    5b6f5e5005

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18363
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:Program Filesdotnetsdk3.1.401

Host (useful for support):
  Version: 3.1.7
  Commit:  fcfdef8d6b

.NET Core SDKs installed:
  3.1.401 [C:Program Filesdotnetsdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.21 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.All]
  Microsoft.AspNetCore.App 3.1.7 [C:Program FilesdotnetsharedMicrosoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.7 [C:Program FilesdotnetsharedMicrosoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.7 [C:Program FilesdotnetsharedMicrosoft.WindowsDesktop.App]

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

и dotnet-core-uninstall list списки

 This tool can not uninstall versions of the runtime or SDK that are 
    - SDKs installed using Visual Studio 2019 Update 3 or later.
    - SDKs and runtimes installed via zip/scripts.
    - Runtimes installed with SDKs (these should be removed by removing that SDK).
The versions that can be uninstalled with this tool are:

.NET Core SDKs:
  3.1.401  x64    [Used by Visual Studio. Specify individually or use --force to remove]

.NET Core Runtimes:
  3.1.7  x64
  2.2.7  x64  
  

Я пытался настроить global.json , но, похоже, это не возымело эффекта.

Мой cjsproj выглядит следующим образом (сокращенная версия):

         <Project Sdk="Microsoft.NET.Sdk">
          <PropertyGroup>
            <TargetFramework>netcoreapp3.1</TargetFramework>
            <RootNamespace>DigitalEksamenIntegration.Business</RootNamespace>
            <RuntimeFrameworkVersion>3.1</RuntimeFrameworkVersion>
            <RuntimeIdentifier>win-x64</RuntimeIdentifier>
          </PropertyGroup>

          <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
            <PlatformTarget>AnyCPU</PlatformTarget>
          </PropertyGroup>


          <ItemGroup>
            <Reference Include="EntityFramework">
              <HintPath>..DigitalEksamenIntegration.WebLibEntityFramework.dll</HintPath>
            </Reference>
          </ItemGroup>
          <ItemGroup>
            <Folder Include="Migrations" />
          </ItemGroup>
          <ItemGroup>
            <WCFMetadata Include="Connected Services" />
          </ItemGroup>
          <ItemGroup>
            <None Update="MailReport_Layout.template.txt">
              <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
              <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
            </None>
            <None Update="MailReport_StudentsMissingInRegistrations.template.txt">
              <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
              <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
            </None>
          </ItemGroup>

        </Project>
  

В некоторых отчетах предполагалось, что это проблема с инструментами, поэтому я попытался:

    dotnet tool uninstall -g dotnet-ef
   dotnet tool install -g dotnet-ef --version 3.1.7
  

Но это тоже не сработало.

Приветствуется любая помощь.

Заранее спасибо.

С уважением, Soeren

Ответ №1:

Я нашел решение — или, скорее, обходной путь:

Я отредактировал runtimeconfig.json , который находится в каталоге вывода. В моем случае: binDebugnetcoreapp3.1win-x64<ProjectName>.runtimeconfig.json (замените <ProjectName> на название вашего проекта).

Поле version ранее содержало номер версии 3.1 . Я отредактировал его, чтобы оно содержало значение 3.1.7 :

     {
      "runtimeOptions": {
        "tfm": "netcoreapp3.1",
        "framework": {
          "name": "Microsoft.NETCore.App",
          "version": "3.1.7"
        }
      }
    }
  

И я, наконец, смог перенести свою базу данных.

Ответ №2:

Попробуйте это :

 dotnet tool install -g dotnet-ef --version 3.1.0
  

В вашем проекте porject установка из nuget

 Microsoft.EntityFrameworkCore.Design
  

И затем, --verbose добавляется, чтобы увидеть возможные предупреждения

 dotnet ef migrations add Init --context TransferDbContext --verbose
  

Комментарии:

1. Привет, спасибо за ваш ответ. Я выполнил команду install и Microsoft.EntityFrameworkCore.Design она уже была включена в проект. Я перечислил результат использования --verbose в вопросе, потому что он требовал комментария