带热重载的 dotnet watch run -c $(Configuration)

Oka*_* S. 8 .net c# .net-core blazor hot-reload

我想启动具有特定配置的 Blazor 应用程序并启用热重载。

当我启动时:

dotnet watch
Run Code Online (Sandbox Code Playgroud)

热重载已启用,一切正常。

当我启动时:

dotnet watch run -c Simulation
Run Code Online (Sandbox Code Playgroud)

热重载未激活,并且应用程序会在文件更改时重建。

我尝试启动:

dotnet watch -c Simulation
Run Code Online (Sandbox Code Playgroud)

但它返回“ watch : Exited with error code 1 ”。

如何使用所需的配置和热重载启动我的应用程序?

编辑:

我的 launchSettings.json 文件中的启动配置文件:

 "Dotnet Watch": {
  "commandName": "Executable",
  "executablePath": "C:\\Program Files\\dotnet\\dotnet.exe",
  "commandLineArgs": "watch run -c $(Configuration)",
  "hotReloadProfile": "aspnetcore",
  "workingDirectory": "$(ProjectDir)",
  "launchUrl": "https://localhost:5001;http://localhost:5000",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
}
Run Code Online (Sandbox Code Playgroud)

添加 "hotReloadProfile": "aspnetcore" 不起作用。

我的 dotnet 版本是:

6.0.300-preview.22154.4
Run Code Online (Sandbox Code Playgroud)

编辑2:

我暂时使用环境变量而不是项目配置在模拟配置文件和其他配置文件之间切换,但奇怪的是没有任何解决方案可以使用特定配置文件进行热重载。网上没有任何关于此事的信息。

And*_* M. 4

根据这篇文章,要走的路是添加"hotReloadProfile": "aspnetcore"到你的launchSettings.json像这样:

{
  "profiles": {
    "dotnet": {
      "commandName": "Project"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

并使用dotnet watch run命令调试您的应用程序。

编辑:

从 dotnet sdk 版本开始,6.0.300-preview.22204.3此问题已得到解决,并且首次编辑时显示的配置适用于 Visual Studio 和 JetBrains Rider。Simulation使用名为直接从调试复制的新虚拟配置在 vanila 项目上进行了测试。

也就是说,似乎dotnet cli无法调用此启动配置文件

PS P:\Path\To\Project> dotnet run --launch-profile "Dotnet Watch"
The launch profile "Dotnet Watch" could not be applied.
The launch profile type 'Executable' is not supported.
Run Code Online (Sandbox Code Playgroud)

我的完整版launchSettings.json

PS P:\Path\To\Project> dotnet run --launch-profile "Dotnet Watch"
The launch profile "Dotnet Watch" could not be applied.
The launch profile type 'Executable' is not supported.
Run Code Online (Sandbox Code Playgroud)

编辑#2

在阅读了@mlhDev的评论后,我再次尝试了这个配置,使用.NET 6.0.400(稳定,不是预发布)和热重载似乎有效。

查看GIF PoC