I am experimenting with visual studio code, .net core 2.2 and entityframework all in one mix.
I do the following steps:
1) create new sln
dotnet new sln --name MySln
2) create a webapi:
dotnet new webapi --name api
3) create a class lib:
dotnet new classlib --name Api.DB
Add references to the projects:
dotnet sln "MyApi.sln" add "api/api.csproj"
dotnet sln "MyApi.sln" add "Api.DB/Api.DB.csproj"
dotnet add reference ../Api.DB/Api.DB.csproj
In the classlib I add the following:
<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:
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]
EDIT:
forgot to mention that when comenting out all my packages in the classlib like so:
<!-- <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:
Startup project 'Api.DB.csproj' targets framework '.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; or, update this project to cross-target .NET Core or .NET Framework. For more information on using the EF Core Tools with .NET Standard projects, see 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:
<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
<RuntimeFrameworkVersion>2.0.5</RuntimeFrameworkVersion>
But I am targeting .netcore 2.2 so I had to change the targetframework to:
<TargetFrameworks>netcoreapp2.2;netstandard2.0</TargetFrameworks>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.