launchSettings.json说明

简介

.Net Core程序在新建项目时,会在默认项目下新建Properties\launchSettings.json文件,对于刚入门的开发者来说,对于文件有什么作用和如何配置会存在一些疑惑;

详细配置说明

{
  使用IIS Express启动配置
  "iisSettings": {
    "windowsAuthentication": false,  //是否启用 Windows 身份验证
    "anonymousAuthentication": true,  //IIS是否启用匿名身份验证
    "iisExpress": {
      "applicationUrl": "http://localhost:63313/", /指定 IIS 服务器的地址
      "sslPort": 0 //指定IIS 服务器的https端口
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress", //命令名:IIS启动
      "launchBrowser": true, //是否自动启动浏览器,填写1或true表示启动,0或false为不启动
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development" //设置环境变量,当前环境设为开发环境
      }
    },
    "APIGateway": {
      "commandName": "Project", //命令名:项目启动
      "launchBrowser": true, //是否自动启动浏览器
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development" //设置环境变量,当前环境设为开发环境
      },
      "applicationUrl": "http://localhost:5000"  //浏览器默认打开位置 http://localhost:5000
    },
    ///使用docker启动配置
    "Docker": {
      "commandName": "Docker", //命令名:DOkcer启动
      "launchBrowser": true, //是否自动启动浏览器
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", //指定 项目启动的地址
      "publishAllPorts": true
    }
  }
}

最终效果就是我们可以在启动调试的时候选择不同的环境来做调试
在这里插入图片描述

完整版本

官方提供launchSettings.json文件的完整配置项说明,可以根据实际使用需要添加需要的属性

{
  "title": "JSON schema for the ASP.NET LaunchSettings.json files.",
  "$schema": "http://json-schema.org/draft-04/schema#",

  "type": "object",

  "definitions": {
    "profile": {
      "type": "object",
      "allOf": [ { "$ref": "#/definitions/profileContent" } ],
      "required": [ "commandName" ]
    },
    "iisSetting": {
      "type": "object",
      "allOf": [ { "$ref": "#/definitions/iisSettingContent" } ]
    },

    "iisSettingContent": {
      "properties": {
        "windowsAuthentication": {
          "type": "boolean",
          "description": "Set to true to enable windows authentication for your site in IIS and IIS Express.",
          "default": false
        },
        "anonymousAuthentication": {
          "type": "boolean",
          "description": "Set to true to enable anonymous authentication for your site in IIS and IIS Express.",
          "default": true
        },
        "iisExpress": {
          "type": "object",
          "description": "Site settings to use with IISExpress profiles.",
          "allOf": [ { "$ref": "#/definitions/iisBindingContent" } ]
        },
        "iis": {
          "type": "object",
          "description": "Site settings to use with IIS profiles.",
          "allOf": [ { "$ref": "#/definitions/iisBindingContent" } ]
        }
      }
    },

    "iisBindingContent": {
      "properties": {
        "applicationUrl": {
          "type": "string",
          "format": "uri",
          "description": "The URL of the web site.",
          "default": ""
        },
        "sslPort": {
          "type": "integer",
          "maximum": 65535,
          "minimum": 0,
          "description": "The SSL Port to use for the web site.",
          "default": 0
        }
      }
    },

    "profileContent": {
      "properties": {
        "commandName": {
          "type": "string",
          "description": "Identifies the debug target to run.",
          "default": "",
          "minLength": 1
        },
        "commandLineArgs": {
          "type": "string",
          "description": "The arguments to pass to the target being run.",
          "default": ""
        },
        "executablePath": {
          "type": "string",
          "description": "An absolute or relative path to the executable.",
          "default": ""
        },
        "workingDirectory": {
          "type": "string",
          "description": "Sets the working directory of the command."
        },
        "launchBrowser": {
          "type": "boolean",
          "description": "Set to true if the browser should be launched.",
          "default": false
        },
        "launchUrl": {
          "type": "string",
          "description": "The relative URL to launch in the browser."
        },
        "environmentVariables": {
          "type": "object",
          "description": "Set the environment variables as key/value pairs.",
          "additionalProperties": {
            "type": "string"
          }
        },
        "applicationUrl": {
          "type": "string",
          "description": "A semi-colon delimited list of URL(s) to configure for the web server."
        },
        "nativeDebugging": {
          "type": "boolean",
          "description": "Set to true to enable native code debugging.",
          "default": false
        },
        "externalUrlConfiguration": {
          "type": "boolean",
          "description": "Set to true to disable configuration of the site when running the Asp.Net Core Project profile.",
          "default": false
        },
        "use64Bit": {
          "type": "boolean",
          "description": "Set to true to run the 64 bit version of IIS Express, false to run the x86 version.",
          "default": false
        }
      }
    }
  },

  "properties": {
    "profiles": {
      "type": "object",
      "description": "A list of debug profiles",
      "additionalProperties": {
        "$ref": "#/definitions/profile"
      }
    },
    "iisSettings": {
      "type": "object",
      "description": "IIS and IIS Express settings",
      "allOf": [ { "$ref": "#/definitions/iisSettingContent" } ]
    }
  }
}

通过GUI来修改配置

我们也可以在项目右键属性-调试中来新建/修改调试环境,修改完的配置也要同步到launchSettings.json文件中

总结说明

launchSettings.json只要时让我们可以配置调试时的环境,以什么模式启动,启动时的地址和端口是什么等信息。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值