官方使用手册
自动保存整理代码
首选项 ->文本编辑器 ->行为
在解决方案中搜索
shift+command+F
程序包管理器控制平台
Visual Studio for Mac 或 Visual Studio Code 中未提供该控制台。参考->
🉑️通过mac自带的终端进行操作.
当操作的时候发现dotnet ef命令并不被支持。
Could not execute because the specified command or file was not found.
需要安装工具,参考->
dotnet tool install --global dotnet-ef
# 可卸载
dotnet tool uninstall --global dotnet-ef
dotnet tool list -g
# 设置环境变量
export PATH="$PATH:$HOME/.dotnet/tools/"
# dotnet ef OK
dotnet ef
_/\__
---==/ \\
___ ___ |. \|\
| __|| __| | ) \\\
| _| | _| \_/ | //|\\
|___||_| / \\\/\\
安装成功之后,可操作EntityFrameworkCore
# EntityFrameworkCore项目路径
cd xxx.EntityFrameworkCore
# = add-migration "update OU"
dotnet ef migrations add "update OU"
# = 多个Context时需指定
dotnet ef migrations add initail -c XXDbContext
dotnet ef migrations list
dotnet ef migrations remove
# = update-database
dotnet ef database update
dotnet ef database update -c
# = install-package
dotnet add package -h|--help
database update 之后将生成db文件,种子数据在运行时生成。
注意⚠️:
因为我配置的是sqlite数据库,连接的数据库路径为相对路径。
{
"ConnectionStrings": {
"Default": "Server=localhost; Database=AprilDb; Trusted_Connection=True;",
"SqliteCnn": "Data Source=AprilDb.db;"
},
当解决方案是由多个程序集组成时,会有路径冲突问题。
我的程序集名称如下:
April.Application
April.Core
# migrations
April.EntityFrameworkCore
April.Migrator
April.Web.Core
# configure database string
April.Web.Host
在windows下,只在April.Web.Host生成一个db文件。而在mac下,同样的配置,database update时在April.EntityFrameworkCore生成一个文件,而运行时候(种子数据写入)在April.Web.Host生成一个空db文件。
所以修改连接路径如下:
{
"ConnectionStrings": {
"Default": "Server=localhost; Database=AprilDb; Trusted_Connection=True;",
"SqliteCnn": "Data Source=../April.EntityFrameworkCore/AprilDb.db;"
},
abp中nswag的使用
refresh.bat只能在windows下生成代理文件,但是refresh.bat内的内容可在mac下运行。
cd nswag
../node_modules/.bin/nswag run
# or
./node_modules/.bin/nswag run ./nswag/service.config.nswag
或者在package.json中添加执行命令
"nswag": "./node_modules/.bin/nswag run nswag/service.config.nswag"
cd ./node_modules/.bin/nswag默认的netcore版本是2.1,可以将版本号改为高版本后后再运行
#!/usr/bin/env node
"use strict";
var defaultCoreVersion = "31";
运行npm run nswag。
> ng-alain@8.9.2 nswag /Users/xxx/projects/DotNet/April/alain
> nswag run nswag/service.config.nswag
NSwag NPM CLI
NSwag command line tool for .NET Core NetCore31, toolchain v13.6.1.0 (NJsonSchema v10.1.21.0 (Newtonsoft.Json v12.0.0.0))
Visit http://NSwag.org for more information.
NSwag bin directory: /Users/xxx/projects/DotNet/April/alain/node_modules/nswag/bin/binaries/NetCore31
Executing file 'nswag/service.config.nswag' with variables ''...
Done.
Duration: 00:00:02.0827282