我已經為這個問題使用了一段時間的解決方法,但我想我會在網上詢問,看看是否有人對我想要實作的目標有任何提示或替代方法。
我有一個非常基本的核心 3.1 MVC 設定,其中包含如下設定檔案:
應用設定.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
appsettings.Development.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
appsettings.Local.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=new-test-site;Trusted_Connection=True;"
}
}
在launchsettings.json我有幾個組態檔設定如下:
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"new_test_site_local": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Local"
}
},
"new_test_site_dev": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
所以在我看來,當我使用 PMC 進行設定時$aspnetcore_environment="Local",應該允許我的專案以appsettings.Local.json(例如連接字串)值優先運行。
但它似乎沒有這樣做?dev如果我將“本地”連接字串復制粘貼到或“正常”應用程式設定中,我只能讓它作業。
如何以我的本地設定作為目標運行命令add-migration?update-database!
uj5u.com熱心網友回復:
使用 PowerShell 語法設定環境變數:
$env:aspnetcore_environment="Local"
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/455322.html
標籤:C# 实体框架 实体框架核心 ef-code-first
