asp.net core for vs code
dotnet new --help 查询命令帮助
D:\github\test2>dotnet run 启动web程序
dotnet build 编译代码
dotnet restore 还原包
dotnet publish 发布项目
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 }); } } }
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" } },
①安装nuget
② ctrl + shift +P 选择nuget,然后输入包名称回车下载
③包版本变更
打开.csproj文件,直接更改PackageReference下的Version
然后dotnet restore
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【打印出数据库变更脚本】
需要在工程文件中加入
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2"/> 和 <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.2"/>
dotnet ef migrations add init -o Data/Migrations
以后再添加不用使用 -o Data/Migrations 直接会添加在Data/Migrations文件夹下
①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" } }