.NET Core 配置多个环境设置
🏷️ .NET Core
appsettings.json
json
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"spring": {
"application": {
"name": "octopus-cloud-net-user"
}
},
"eureka": {
"client": {
"serviceUrl": "http://localhost:9871/eureka/",
"shouldRegisterWithEureka": true,
"shouldFetchRegistry": false,
"validateCertificates": false
},
"instance": {
"hostName": "localhost"
}
},
"apollo": {
"AppId": "netcore-config-test",
"MetaServer": "http://192.168.0.52:8080"
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
appsettings.Development.json
json
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"eureka": {
"instance": {
"port": 9102,
"instanceId": "octopus-cloud-net-user:9102"
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
appsettings.TestD.json
json
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"eureka": {
"instance": {
"port": 9103,
"instanceId": "octopus-cloud-net-user:9103"
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
上面文件名中的 Development 和 TestD 就是环境变量。
Properties/launchSettings.json
json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:9102",
"sslPort": 0
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/user",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Octopus.Cloud.User": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/user",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:9102"
},
"TestD": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/user",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "TestD"
},
"applicationUrl": "http://localhost:9103"
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
通过 dotnet run
启动程序,参数中的 --launch-profile TestD
则是指定 launchSettings.json 中的 profiles.TestD
bash
dotnet run --launch-profile TestD
1