错误您的启动项目未引用 Microsoft.EntityFrameworkCore.Design
Error Your startup project doesn't reference Microsoft.EntityFrameworkCore.Design
我有一个项目是web.API。
我尝试进行迁移,但它不起作用。我找到了很多解决方案,但它们都没有用。我也查看了在 Whosebug 上打开的类似线程并按照所说的做了,但没有得到任何结果。
class 库有 dbcontext .csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="Repositories\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\SharedNote.Domain\SharedNote.Domain.csproj" />
</ItemGroup>
</Project>
我的数据库上下文class
using Microsoft.EntityFrameworkCore;
using SharedNote.Domain.Entites;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace SharedNotes.Persistence.Context
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
protected ApplicationDbContext()
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer("Data Source=localhost;Initial Catalog=SHARED_NOTE;User ID=sa;Password=stacoverflow");
}
}
public DbSet<College> Colleges { get; set; }
public DbSet<FileDocument> FileDocuments { get; set; }
public DbSet<Department> Departments { get; set; }
}
}
我的 web.apı csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\SharedNote.Application\SharedNote.Application.csproj" />
<ProjectReference Include="..\..\Infrastructure\SharedNotes.Persistence\SharedNotes.Persistence.csproj" />
</ItemGroup>
</Project>
来自 pmc 的错误
注意:我的默认项目是pmc
中的“src/Infrastructure/SharedNotes.Persistence”
PM> add-migration initial-v1.0
Build started...
Build succeeded.
Your startup project 'ShareableNote.API' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.
PM>
您的 api 项目应该有 Microsoft.EntityFrameworkCore.Design
ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.12">
</ItemGroup>
据我了解,这是您的第一次迁移,因此在控制台管理器中 select 您的 dbcontext 项目并尝试此操作
Add-Migration InitialCreate
我有一个项目是web.API。 我尝试进行迁移,但它不起作用。我找到了很多解决方案,但它们都没有用。我也查看了在 Whosebug 上打开的类似线程并按照所说的做了,但没有得到任何结果。
class 库有 dbcontext .csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="Repositories\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\SharedNote.Domain\SharedNote.Domain.csproj" />
</ItemGroup>
</Project>
我的数据库上下文class
using Microsoft.EntityFrameworkCore;
using SharedNote.Domain.Entites;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace SharedNotes.Persistence.Context
{
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
protected ApplicationDbContext()
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer("Data Source=localhost;Initial Catalog=SHARED_NOTE;User ID=sa;Password=stacoverflow");
}
}
public DbSet<College> Colleges { get; set; }
public DbSet<FileDocument> FileDocuments { get; set; }
public DbSet<Department> Departments { get; set; }
}
}
我的 web.apı csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\SharedNote.Application\SharedNote.Application.csproj" />
<ProjectReference Include="..\..\Infrastructure\SharedNotes.Persistence\SharedNotes.Persistence.csproj" />
</ItemGroup>
</Project>
来自 pmc 的错误
注意:我的默认项目是pmc
中的“src/Infrastructure/SharedNotes.Persistence”PM> add-migration initial-v1.0
Build started...
Build succeeded.
Your startup project 'ShareableNote.API' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.
PM>
您的 api 项目应该有 Microsoft.EntityFrameworkCore.Design
ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.12">
</ItemGroup>
据我了解,这是您的第一次迁移,因此在控制台管理器中 select 您的 dbcontext 项目并尝试此操作
Add-Migration InitialCreate