Microsoft.AspNetCore.Hosting.Abstractions清单定义与程序集引用不匹配

时间:2017-07-04 13:52:36

标签: .net-core entity-framework-core

当我在类库中运行Entitfy框架核心命令add-migration MyMigrationName时,我收到以下错误

  

无法加载文件或程序集   ' Microsoft.AspNetCore.Hosting.Abstractions,版本= 1.1.1.0,   Culture = neutral,PublicKeyToken = adb9793829ddae60'或其中一个   依赖。定位程序集的清单定义没有   匹配程序集引用。 (HRESULT异常:0x80131040)

有趣的是我的申请中没有提及抽象。

这是我的csproj

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

    <PropertyGroup Label="Globals">
      <SccProjectName>SAK</SccProjectName>
      <SccProvider>SAK</SccProvider>
      <SccAuxPath>SAK</SccAuxPath>
      <SccLocalPath>SAK</SccLocalPath>
    </PropertyGroup>

    <PropertyGroup>
      <TargetFramework>net452</TargetFramework>
      <AssemblyName>MyProjectName</AssemblyName>
      <OutputType>Library</OutputType>
      <PackageId>MyProjectName</PackageId>
      <NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
      <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
      <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
      <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
      <RootNamespace>MyProjectName</RootNamespace>
    </PropertyGroup>
    <ItemGroup>
      <None Update="appsettings.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      </None>
    </ItemGroup>
    <ItemGroup>
      <PackageReference Include="DocumentFormat.OpenXml" Version="2.5.0" />
      <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.2" />
      <PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
      <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />
      <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
      <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" />
      <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" />
      <PackageReference Include="System.Collections" Version="4.3.0" />
      <PackageReference Include="System.Linq" Version="4.3.0" />
      <PackageReference Include="System.Runtime" Version="4.3.0" />
      <PackageReference Include="System.Threading" Version="4.3.0" />
    </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
    <Reference Include="System" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
  </ItemGroup>
</Project>

1 个答案:

答案 0 :(得分:4)

为了让NuGet将适当的绑定重定向添加到类库项目,您需要将以下内容添加到*.csproj文件中。

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>