.NET 6 Preview 4 以降で ASP.NET Core プロジェクトを作成するとデフォルトの起動プロファイルが Kestrel になります。
devblogs.microsoft.com
以下のように、デフォルトの起動プロファイルと、プロファイルの並び順に違いがあります。
.NET 5 (VS2019) | .NET 6 (VS2022 Preview) |
---|---|
デフォルトの起動プロファイルは、単純に、[AppName].csproj.user の ActiveDebugProfile の値で決まりますので、.NET 5 でも値を修正すれば デフォルトの起動プロファイルが Kestrel になります。
Kestrel の方が軽いですし、クロスプラットフォームなので、既存の .NET 5 のプロジェクトでも デフォルトの起動プロファイルを Kestrel に変更したい場合もあると思います。
.NET 5 の例
WebApp2019.csproj.user 初期値(IIS Express デフォルト)
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <DebuggerFlavor>ProjectDebugger</DebuggerFlavor> </PropertyGroup> <PropertyGroup> <ActiveDebugProfile>IIS Express</ActiveDebugProfile> </PropertyGroup> </Project>
WebApp2019.csproj.user 変更後(Kestrel デフォルト)
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <DebuggerFlavor>ProjectDebugger</DebuggerFlavor> </PropertyGroup> <PropertyGroup> <ActiveDebugProfile>WebApp2019</ActiveDebugProfile> </PropertyGroup> </Project>
起動プロファイルが Kestrel に変更されました。
起動プロファイルの並び順については、[AppName]\Properties\launchSettings.json 内の記載順で決まりますので、こちらも順番を入れ替えれば、 Kestrel, IIS Express, WSL の並び順を自由に入れ替えできます。
launchSettings.json 初期値(IIS Express が最初に記載されている)
{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:27769", "sslPort": 44341 } }, "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "WebApp2019": { "commandName": "Project", "launchBrowser": true, "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": "true", "applicationUrl": "https://localhost:5001;http://localhost:5000" }, "WSL": { "commandName": "WSL2", "launchBrowser": true, "launchUrl": "https://localhost:5001/swagger", "environmentVariables": { "ASPNETCORE_URLS": "https://localhost:5001;http://localhost:5000", "ASPNETCORE_ENVIRONMENT": "Development" }, "distributionName": "" } } }
JSON の記載順通り IIS Express , WebApp2019(Kestrel) , WSL の順番になります。
launchSettings.json 順番入れ替え済み(Kestrel が最初に記載されている)
{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:27769", "sslPort": 44341 } }, "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { "WebApp2019": { "commandName": "Project", "launchBrowser": true, "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": "true", "applicationUrl": "https://localhost:5001;http://localhost:5000" }, "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "WSL": { "commandName": "WSL2", "launchBrowser": true, "launchUrl": "https://localhost:5001/swagger", "environmentVariables": { "ASPNETCORE_URLS": "https://localhost:5001;http://localhost:5000", "ASPNETCORE_ENVIRONMENT": "Development" }, "distributionName": "" } } }
こちらも、入れ替えた JSON の記載順通り WebApp2019(Kestrel) , IIS Express , WSL の順番になります。
小技ですが、必要になったときに結構忘れたりしますので、備忘録として残しておきました。