Python和.NET交互-与最新DeepSeekV3.2大模型对话
2026/7/1 17:47:36
launchSettings.json完整步骤必须放在项目下的Properties 文件夹内:项目根目录/Properties/launchSettings.json
PropertieslaunchSettings.jsonDOTNET_ENVIRONMENT,不是 ASPNETCORE)json
{ "$schema": "https://json.schemastore.org/launchsettings.json", "profiles": { // 开发环境启动配置 "WinFormApp-Development": { "commandName": "Project", "dotnetRunMessages": true, "environmentVariables": { "DOTNET_ENVIRONMENT": "Development", // 可在这里临时覆盖配置 "ConnectionStrings__DefaultDb": "Server=.;Database=DevDB;Uid=sa;Pwd=123456" } }, // 测试环境 "WinFormApp-Staging": { "commandName": "Project", "dotnetRunMessages": true, "environmentVariables": { "DOTNET_ENVIRONMENT": "Staging" } }, // 本地模拟生产 "WinFormApp-Production": { "commandName": "Project", "dotnetRunMessages": true, "environmentVariables": { "DOTNET_ENVIRONMENT": "Production" } } } }WinFormApp-Development/WinFormApp-Staging/WinFormApp-Productionappsettings.Development.jsonDOTNET_ENVIRONMENTASPNETCORE_ENVIRONMENT只给 Web 项目用,WinForms/WPF/ 控制台不识别。launchSettings.json只在 VS 调试、dotnet run 时生效程序发布打包后不会带上此文件,服务器部署需要手动设置系统环境变量。__双下划线,对应 json 的:DOTNET_ENVIRONMENT值:DevelopmentlaunchSettings.json运行
var host = Host.CreateDefaultBuilder(args) .ConfigureServices((ctx, services) => { // 获取当前环境 string env = ctx.HostingEnvironment.EnvironmentName; bool isDev = ctx.HostingEnvironment.IsDevelopment(); }) .Build();项目根目录 ├─ appsettings.json ├─ appsettings.Development.json ├─ appsettings.Staging.json ├─ appsettings.Production.json └─ Properties/ └─ launchSettings.json选中每个appsettings*.json→ 属性 →复制到输出目录:如果较新则复制