C# 如何创建一个既有auth又有EF的新dotnet核心应用程序?
我可以使用命令行创建具有身份验证/标识的新dotnetcore应用程序:C# 如何创建一个既有auth又有EF的新dotnet核心应用程序?,c#,.net-core,C#,.net Core,我可以使用命令行创建具有身份验证/标识的新dotnetcore应用程序: dotnet new mvc --auth Individual 如何在项目中也包括实体框架?TL;博士 您的项目中已经有了它 长格式答案 创建应用程序后,它应该具有实体框架作为依赖项。我假设您正在运行.NETCore2.0SDK 这是我机器的输出 $ dotnet new mvc --auth Individual --name testForStackOverflow The template "ASP.NET Co
dotnet new mvc --auth Individual
如何在项目中也包括实体框架?TL;博士
您的项目中已经有了它
长格式答案
创建应用程序后,它应该具有实体框架作为依赖项。我假设您正在运行.NETCore2.0SDK
这是我机器的输出
$ dotnet new mvc --auth Individual --name testForStackOverflow
The template "ASP.NET Core Web App (Model-View-Controller)" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/template-3pn for details.
Processing post-creation actions...
Running 'dotnet restore' on testForStackOverflow/testForStackOverflow.csproj...
Restoring packages for testForStackOverflow/testForStackOverflow.csproj...
Restore completed in 40.17 ms for testForStackOverflow/testForStackOverflow.csproj.
Restore completed in 40.17 ms for testForStackOverflow/testForStackOverflow.csproj.
Restore completed in 25.25 ms for testForStackOverflow/testForStackOverflow.csproj.
Generating MSBuild file testForStackOverflow/obj/testForStackOverflow.csproj.nuget.g.props.
Generating MSBuild file testForStackOverflow/obj/testForStackOverflow.csproj.nuget.g.targets.
Restore completed in 2.84 sec for testForStackOverflow/testForStackOverflow.csproj.
Restore succeeded.
然后我看一看生成的csproj:
$ cd testForStackOverflow/
~/testForStackOverflow$ ls
app.db Data Startup.cs
appsettings.Development.json Extensions testForStackOverflow.csproj
appsettings.json Models Views
bower.json obj wwwroot
bundleconfig.json Program.cs
Controllers Services
~/testForStackOverflow$ cat testForStackOverflow.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<UserSecretsId>aspnet-testForStackOverflow-AD382505-1A70-4A75-8059-1E0E3897A088</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<None Update="app.db" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
</Project>
$cd testForStackOverflow/
~/testForStackOverflow$ls
app.db Data Startup.cs
appsettings.Development.json扩展testForStackOverflow.csproj
appsettings.json模型视图
bower.json obj wwwroot
bundleconfig.json Program.cs
管制员服务
~/testForStackOverflow$cat testForStackOverflow.csproj
netcoreapp2.0
aspnet-testForStackOverflow-AD382505-1A70-4A75-8059-1E0E3897A088
csproj的重要路线如下:
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
这是一个参考。此软件包包含所有常见的ASP.NET核心NuGet软件包,包括Entity Framework Core-根据NuGet的此屏幕截图(几分钟前捕获)
这意味着包还原操作的一部分包括将EF Core还原到项目中
我想说的是,你应该看看EF核心-链接应该直接带你到标有“模型”的部分。您不需要上一节中的内容(标记为“获取实体框架核心”),因为您已经有了它
当然,如果您使用的是.NET Core SDK的1.x版,那么情况就稍有不同。我想看看Jon Skeet关于如何提问的博客文章。codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question你提供了足够的信息让我给你一个答案,但这个问题缺少一点细节。例如,您使用的是哪个版本的.NET核心SDK?