簡體   English   中英

如何解決“System.Runtime”和“netstandard”中都存在“AssemblyCompanyAttribute”類型?

[英]How to resolve The type 'AssemblyCompanyAttribute' exists in both 'System.Runtime,' and 'netstandard'?

我正在嘗試使用visual studio代碼,.net core 2.2和entityframework。

我執行以下步驟:

1)創造新的sln

dotnet new sln --name MySln

2)創建一個webapi:

dotnet new webapi --name api

3)創建一個類lib:

dotnet new classlib --name Api.DB

添加對項目的引用:

dotnet sln“MyApi.sln”添加“api / api.csproj”

dotnet sln“MyApi.sln”添加“Api.DB / Api.DB.csproj”

dotnet添加引用../Api.DB/Api.DB.csproj

在classlib中我添加以下內容:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
     <RuntimeFrameworkVersion>2.0.5</RuntimeFrameworkVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4"/>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.4"/>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4"/>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final"/> 
  </ItemGroup>
     <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />
  </ItemGroup>
</Project>

問題我不明白這個但是我在classlib中收到以下錯誤:

類型'AssemblyCompanyAttribute'存在於'System.Runtime,Version = 4.1.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'和'netstandard,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = cc7b13ffcd2ddd51'(CS0433)[Api] 。D B]

在此輸入圖像描述

編輯:

忘記提及當我在classlib中填寫我的所有包時,如下所示:

<!-- <PackageReference Include="Microsoft.EntityFrameworkCore" Version="*"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="*"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="*"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="*"/> -->

然后錯誤消失了,這讓我更加困惑? 包裹有錯誤嗎?

當我刪除它們並嘗試scafoled我的數據庫上下文然后我得到:

啟動項目'Api.DB.csproj'的目標是框架'.NETStandard'。 沒有與此框架關聯的運行時,並且無法直接執行以其為目標的項目。 要將Entity Framework Core .NET命令行工具與此項目一起使用,請添加一個針對引用此項目的.NET Core或.NET Framework的可執行項目,並使用--startup-project將其設置為啟動項目; 或者,更新此項目以跨目標.NET Core或.NET Framework。 有關將EF Core Tools與.NET Standard項目一起使用的詳細信息,請參閱https://go.microsoft.com/fwlink/?linkid=2034781

我一直在努力解決我的錯誤一段時間,我最終找到了解決方案。

@Lesiak在評論中給我鏈接后,我將以下內容放入我的classlib中:

  <PropertyGroup>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup> 
  <PropertyGroup>
    <EnableDefaultRazorTargetAssemblyInfoAttributes>false</EnableDefaultRazorTargetAssemblyInfoAttributes>
  </PropertyGroup> 

這解決了原始錯誤。

但是我關注的指南是.net core 2.0所以我在classlib中包含了以下內容

<RuntimeFrameworkVersion>2.0.5</RuntimeFrameworkVersion> 

但我的目標是.netcore 2.2所以我不得不將targetframework更改為:

  <TargetFrameworks>netcoreapp2.2;netstandard2.0</TargetFrameworks>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM