![](/img/trans.png)
[英]FileNotFoundException exists in both System.IO and System.Runtime
[英]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.