尝试运行 asp.net 核心项目时出现此错误。
缺少一个或多个编译参考。确保项目引用“Microsoft.NET.Sdk.web”且 PreserveCompilationContext 属性未设置为 false
EfDemo.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
</Project>
家庭控制器.cs
namespace EfDemo.Controllers
{
public class HomeController : Controller
{
async public Task<IActionResult> Index()
{
using (var context = new EFCoreWebDemoContext())
{
var model = await context.Authors.AsNoTracking().ToListAsync();
return View(model);
}
}
}
}
四季花海
相关分类