创建项目
我现在安装的是VS2019 企业版,安装的时候使用的密钥是BF8Y8-GN2QH-T84XB-QVY3B-RC4DF,一起放在这里,万一用得上哩。
- 打开VS,文件按钮->新建->项目
- 语言选择为C#,同时选择为
ASP.Net Core Web 应用程序
,点击下一步。
- 填写项目名称,再创建,下面图片中,选择
3.1
版本,模板选择Web 应用程序
,最后点击创建。
- 创建完后,项目结构如下。
安装并应用NewLife.Cube.Core
这里就是我们的重头戏拉,伟大的魔方登场,首先还是要感谢大石头GG拉。
- 右键点击项目中依赖项->点击管理NuGet程序包->搜索框输入
NewLife.Cube.Core
,选中搜索结果,点击安装。
- Startup.cs文件修改如下。注意更改空间名jsdhh要改成你自己的 ``` using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using NewLife.Cube;
namespace jsdhh { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; }
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews(); // 2020-12-26添加
services.AddCube();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseCube(env);
}
}
} ``` 然后我测试生成解决方案,没有报错,按F5,在弹出的IE地址无法显示的后面,加个/admin,成功拉,输入用户名密码admin注意:初始化运行需要下载静态资源和驱动,生成菜单,所以出现异常或者页面样式不对,都是正常现象,稍等或重新运行项目即可。