简体   繁体   English

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

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

I am experimenting with visual studio code, .net core 2.2 and entityframework all in one mix. 我正在尝试使用visual studio代码,.net core 2.2和entityframework。

I do the following steps: 我执行以下步骤:

1) create new sln 1)创造新的sln

dotnet new sln --name MySln dotnet new sln --name MySln

2) create a webapi: 2)创建一个webapi:

dotnet new webapi --name api dotnet new webapi --name api

3) create a class lib: 3)创建一个类lib:

dotnet new classlib --name Api.DB dotnet new classlib --name Api.DB

Add references to the projects: 添加对项目的引用:

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

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

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

In the classlib I add the following: 在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>

Problem I dont understand this But i am getting the following error in the classlib: 问题我不明白这个但是我在classlib中收到以下错误:

The type 'AssemblyCompanyAttribute' exists in both 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' (CS0433) [Api.DB] 类型'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]

在此输入图像描述

EDIT: 编辑:

forgot to mention that when comenting out all my packages in the classlib like so: 忘记提及当我在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="*"/> -->

Then the error dissapeares which confuses me even more? 然后错误消失了,这让我更加困惑? is there an error with the packages? 包裹有错误吗?

When I remove them and try to scafoled my db context then I get: 当我删除它们并尝试scafoled我的数据库上下文然后我得到:

Startup project 'Api.DB.csproj' targets framework '.NETStandard'. 启动项目'Api.DB.csproj'的目标是框架'.NETStandard'。 There is no runtime associated with this framework, and projects targeting it cannot be executed directly. 没有与此框架关联的运行时,并且无法直接执行以其为目标的项目。 To use the Entity Framework Core .NET Command-line Tools with this project, add an executable project targeting .NET Core or .NET Framework that references this project, and set it as the startup project using --startup-project; 要将Entity Framework Core .NET命令行工具与此项目一起使用,请添加一个针对引用此项目的.NET Core或.NET Framework的可执行项目,并使用--startup-project将其设置为启动项目; or, update this project to cross-target .NET Core or .NET Framework. 或者,更新此项目以跨目标.NET Core或.NET Framework。 For more information on using the EF Core Tools with .NET Standard projects, see https://go.microsoft.com/fwlink/?linkid=2034781 有关将EF Core Tools与.NET Standard项目一起使用的详细信息,请参阅https://go.microsoft.com/fwlink/?linkid=2034781

I have been working on resolving my error for some time now and I finaly came to a solution. 我一直在努力解决我的错误一段时间,我最终找到了解决方案。

After @Lesiak gave me the link in the comments I put the following into my classlib: @Lesiak在评论中给我链接后,我将以下内容放入我的classlib中:

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

This resolved the original error. 这解决了原始错误。

However The guide i was following for this was for .net core 2.0 so I included the following in the classlib 但是我关注的指南是.net core 2.0所以我在classlib中包含了以下内容

<RuntimeFrameworkVersion>2.0.5</RuntimeFrameworkVersion> 

But I am targeting .netcore 2.2 so I had to change the targetframework to: 但我的目标是.netcore 2.2所以我不得不将targetframework更改为:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.IO和System.Runtime中都存在FileNotFoundException - FileNotFoundException exists in both System.IO and System.Runtime .NET Core 3.0 迁移错误 IAsyncEnumerable<t> System.Interactive.Async 和 System.Runtime 中都存在</t> - .NET Core 3.0 migration error IAsyncEnumerable<T> exists in both System.Interactive.Async and System.Runtime 无法解析 UWP 应用中 System.Runtime 的范围 - Unable to resolve scope of System.Runtime in UWP App .NET Framework:如何更新 System.Runtime? - .NET Framework: How to update System.Runtime? TypeLoadException : 无法解析类型(来自 typeref、类/程序集 System.IO.Stream、System.Runtime、Version=4.2.2.0、Culture=neutral) - TypeLoadException : Could not resolve type (from typeref, class/assembly System.IO.Stream, System.Runtime, Version=4.2.2.0, Culture=neutral) 引用类型'Assembly'声明它在'System.Runtime'中定义,但找不到它 - Reference to type 'Assembly' claims it is defined in 'System.Runtime', but it could not be found 类型 [Type] 存在于 [Assembly1] 和 [netstandard 2.0 assembly] - The type [Type] exists in both [Assembly1] and [netstandard 2.0 assembly] “IEnumerable &lt;&gt;”类型在未引用的程序集中定义。 System.Runtime - The type 'IEnumerable<>' is defined in an assembly that is not referenced. System.Runtime 引用类型&#39;CancellationToken&#39;声称它在&#39;System.Runtime&#39;中定义 - Reference to type 'CancellationToken' claims it is defined in 'System.Runtime' 命名空间“System.Runtime”中不存在类型或命名空间名称“缓存” - The type or namespace name 'Caching' does not exist in the namespace 'System.Runtime'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM