Fork me on GitHub

asp.net core for vs code

1,命令

2,模板

3,更换启动浏览器

4,vscode使用nuget

5,使用ef migration

6,配置.net core的工作目录

7,使用dotnet ef migrations命令

8,指定migration生成的目录

9,vscode使用Bower

10,引用项目 

 

 

1,命令

 dotnet new --help 查询命令帮助

 D:\github\test2>dotnet run 启动web程序

 dotnet build 编译代码

 dotnet restore 还原包

 dotnet publish 发布项目

 

2,模板

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using test3.Models;

namespace test3.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
Controller模板

 

3,更换启动浏览器

windows下启动浏览器命令: C:\Windows\System32>cmd.exe /C start http://localhost:5000/api/values 

"launchBrowser": {
                "enabled": true,
                "args": "${auto-detect-url}",
                "windows": {
                    "command": "C:\\Users\\Hunter\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe",
                    "args": "${auto-detect-url}"
                },
                "osx": {
                    "command": "open"
                },
                "linux": {
                    "command": "xdg-open"
                }
            },
更新配置

 

4,vscode使用nuget

①安装nuget

② ctrl + shift +P 选择nuget,然后输入包名称回车下载

③包版本变更

打开.csproj文件,直接更改PackageReference下的Version

然后dotnet restore

 

5,使用ef migration

dotnet ef migrations add initialCreate  Add-Migration【添加更新实体】

dotnet ef database update  Update-Database【向数据库更新】

dotnet ef migrations remove  Remove-Migration【删除最后一个migration文件,前提是该migration文件为update到数据库】

dotnet ef database update LastGoodMigration Update-Database LastGoodMigration【回滚到指定的migration文件。不会删除migration文件。如果不需要migration文件可以通过dotnet ef migrations remove删除掉】

dotnet ef migrations script  Script-Migration【打印出数据库变更脚本】

 

6,配置.net core的工作目录

program:需要执行的dll
cwd:被调试程序的工作目录

 

7,使用dotnet ef migrations命令

需要在工程文件中加入

 <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2"/> 和 <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2"/> 

 

8,指定migration生成的目录

 dotnet ef migrations add init -o Data/Migrations 

以后再添加不用使用  -o Data/Migrations 直接会添加在Data/Migrations文件夹下

 

9,vscode使用Bower

①vscode安装Bower扩展

 Ctrl + Shift +  p 就可以使用Bower了

②在项目中添加.bowerrc文件指定包安装路径

{
    "directory": "wwwroot/lib"
}

③添加bower.json文件

{
  "name": "MvcDemo2",
  "private": true,
  "dependencies": {
    "jquery": "3.1.1",
    "bootstrap": "3.3.7",
    "zTree":"3.5.33"
  }
}

 

10,引用项目

<ItemGroup>
<ProjectReference Include="..\IdentityServer4\IdentityServer4.csproj" />
</ItemGroup>

 

posted on 2018-05-04 17:09  *Hunter  阅读(237)  评论(0编辑  收藏  举报

导航

AmazingCounters.com