vscode 新建cpp文件_VS Code使用命令创建文件

使用dotnet 命令在ASP.NET Core MVC 中创建Controller和View,之前讲解过使用yo 来创建Controller和View。

下面来了解dotnet 命令来创建Controller和View,功能更加强大,更加完整。

结合VS Code 使你能跨平台更好更快速的开发 ASP.NET Core MVC。

也就可以在 Linux 和Mac 中更好的开发ASP.NET Core 应用程序。

创建ASP.NET Core应用程序dotnet new -t web

dotnet restore

dotnet run

创建好以后,我们来添加 Controller和View。

创建使用的dotnet命令为: dotnet aspnet-codegenerator

创建Controller

1.空白Controllerdotnet aspnet-codegenerator controller -name LineZero -outDir Controllers

2.增删查改Controllerdotnet aspnet-codegenerator controller -name LineZero -actions -outDir Controllers

命令增加一个:-actions

3.增删查改+EF Controller

生成增删查改的action 及对应的视图。dotnet aspnet-codegenerator controller -name LineZeroController -m ApplicationUser -dc ApplicationDbContext -outDir Controllers

-m 指的是model

-dc 指 DbContext

4.API Controllerdotnet aspnet-codegenerator controller -name LineZeroController -m ApplicationUser -dc ApplicationDbContext -api -outDir Controllers

增加一个 -api 就代表是生成api controller

更多命令可以参考帮助:dotnet aspnet-codegenerator controller -?

创建View

1.创建View

可以指定什么操作,Create|Edit|Delete|Details|List ,必须填入对应的modeldotnet aspnet-codegenerator view Index List -m ApplicationUser -f -outDir Views\LineZero

这里我们就创建了一个名为:Index   操作为:List 的View

-f 如果存在该文件则覆盖文件。dotnet aspnet-codegenerator 默认是不覆盖文件。

更多命令可以参考帮助:dotnet aspnet-codegenerator view -?

至此命令的展示也就完了。

dotnet aspnet-codegenerator 来源

那么这个命令是从哪里来的呢?dotnet 默认是没有aspnet-codegenerator

在dependencies 节点添加如下:

"dependencies": {

...    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {      "version": "1.0.0-preview2-final",      "type": "build"

},    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {      "version": "1.0.0-preview2-final",      "type": "build"

}

},

然后在 tools 节点添加如下:

"tools": {

...    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {      "version": "1.0.0-preview2-final",      "imports": [        "portable-net45+win8+dnxcore50",        "portable-net45+win8"

]

}

},

dotnet restore

这样也就可以使用 dotnet aspnet-codegenerator 。

上面dotnet new 创建的web 项目可以使用 dotnet aspnet-codegenerator ,是由于项目默认已经给我们添加了对应的节点及引用。

如果你是在Windows 下使用 VS 2015 开发的话,你将得到更好的体验。

使用 VS 2015 打开带有dotnet aspnet-codegenerator的项目,VS 会自动扩展,新增额外添加功能。

在项目右键会发现多了添加 控制器,在Views 文件夹下右键,会多一个 添加 视图。

选择以后就可以添加不同类型的Controller,这个其实也是调用dotnet aspnet-codegenerator 命令。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值