dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.8k stars 450 forks source link

Aspire disregards specified launch-settings commands #4907

Open g-martin772 opened 3 months ago

g-martin772 commented 3 months ago

When running a Project with Aspire locally there is the option to specify a launch profile in the builder.AddProject(string, string), which is being ten being read. After reviewing the code a bit, it appears that only the "applicationUrl" and "commandLineArgs" fields are being evaluated. Personally, I am mostly interested in the "executablePath" field. For example, referencing the dotnet executable to run the project using .NET "dotnet watch" when running locally to enable nice hot reloading (outside of VS, and yes, I am aware of the open SDK issue regarding watch support for aspire).

"Watch": {
      "commandName": "Executable",
      "executablePath": "dotnet",
      "workingDirectory": "$(ProjectDir)",
      "hotReloadEnabled": true,
      "hotReloadProfile": "aspnetcore",
      "commandLineArgs": "watch run",
      "launchBrowser": false,
      "applicationUrl": "http://localhost:4110",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },

This is what I used to do with basically all of my projects and it used to work pretty great so far, and I don't know if I am going insane at that point but I feel like this also used to work when running in Aspire....

It would be cool if the "commandName" and "executablePath" (and maybe some of the other more relevant fields as well) would be interpreted correctly. I think this should only require changes to the builder and how the executable path is being set in the end. I actually tried implementing this myself but it didn't work as expected.

Would this be possible or is running the application directly a strict requirement here?

g-martin772 commented 3 months ago

Could I please get any feedback on this?

davidfowl commented 1 month ago

I think this would break debugging. Maybe that's ok in this situation?

g-martin772 commented 1 month ago

Ahh, yes, thats probably true. But for everyone working outside of visual studio having atleast some sort of hot reloading whould really be great. I know some of thoose things are still being worked on. Whould this be a viable option to consider? Otherwise you can just close the issue.

davidfowl commented 1 month ago

You can use dotnet watch on the apphost project today without changing the launch profile.

g-martin772 commented 1 month ago

Yes, but doesn’t that only apply to the apphost itself? I am talking about making this work for "sub project" aswell that are started using the apphost because you have no control on how it does that internally.

davidfowl commented 1 month ago

No it doesn’t. It’s handled specially

g-martin772 commented 1 month ago

I am on the latest version of .NET 8 and Aspire workloads and then I run the apphost project from the terminal using dotnet watch I only get

 dotnet watch
dotnet watch 🔥 Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload.                 
  💡 Press "Ctrl + R" to restart.                                                                                        
dotnet watch ⌚ Started                                                                                                   
Building...                                                                                                              
C:\dev\work\AspireApp1\AspireApp1.AppHost\AspireApp1.AppHost.csproj : warning NU1903: Package 'System.Text.Json' 8.0.0 has a known high severity vulnerability, https://github.com/advisories/GHSA-hh2w-p6rv-4g7w
C:\dev\work\AspireApp1\AspireApp1.AppHost\AspireApp1.AppHost.csproj : warning NU1903: Package 'System.Text.Json' 8.0.0 has a known high severity vulnerability, https://github.com/advisories/GHSA-hh2w-p6rv-4g7w
info: Aspire.Hosting.DistributedApplication[0]
      Aspire version: 8.2.0+75fdcff28495bdd643f6323133a7d411df71ab70
info: Aspire.Hosting.DistributedApplication[0]
      Distributed application starting.
info: Aspire.Hosting.DistributedApplication[0]
      Application host directory is: C:\dev\work\AspireApp1\AspireApp1.AppHost
info: Aspire.Hosting.DistributedApplication[0]
      Now listening on: https://localhost:15222

instead of what I get when launching it via IDE:

image

Also using the default Aspire App template, even with dotnet watch, it does not recognize file changes to for example the razor home page in the Web Project. I also found this issue which still seems to be not resolved. Am I doing something wrong here?

davidfowl commented 1 month ago

Does it detect changes to .cs files?

g-martin772 commented 1 month ago

Only in the apphost project, it doesn't pick up any other changes.

davidfowl commented 3 weeks ago

We're updating dotnet watch to better handle aspire scenarios (it'll make things like razor files work and it'll be more incremental for aspire), hopefully it will fix these problems.

Follow this issue https://github.com/dotnet/sdk/issues/36971