dotnet / project-system

The .NET Project System for Visual Studio
MIT License
968 stars 386 forks source link

Provide an option to launch external scripts via launchSettings.json #9357

Open alex-jitbit opened 9 months ago

alex-jitbit commented 9 months ago

Currently in Visual Studio 2022 there's no way to execute debug tasks/scripts when testing an ASP.NET Core app locally.

It would be beneficial to be able to launch external tools/scripts/watchers in addition to the main application, when debug session is being started (mainly - watchers)

Examples:

In modern front-end almost everything is being BUILT. Tailwind CSS generates a file, TypeScript is compiled to JavaScript etc.etc. To enable live-reload we need file-watchers to launch these builds. And in Visual Studio there's literally no way to run, for example, a simple npm script when I start debugging a web app.

The only thing we have are MSBuild events, but they can't be used to launch long-running tasks (like file watchers) in parallel with debug.

Currently, if you're a front-end dev that makes a lot of changes to CSS/JS, the only way to update the browser is to run npm run build every time you make any change in your files. This is painful. Or - stop and restart the app altogether, to re-run all the MSBuild scripts.

P.S, Another option would be to offer us a way to hook into Hot Reload events and add custom commands there.

ViIvanov commented 9 months ago
  • launch an npm file-watcher task that compiles LESS/SASS/CSS files
  • launch an npm watcher that minifies JS files
  • launch tailwind-cli process that scans the code for unused utility classes

Why not do it after the build instead of before debugging?

alex-jitbit commented 9 months ago

@ViIvanov watcher processes never "end" so the build will never finish.

kvenkatrajan commented 8 months ago

@sayedihashimi thoughts on this? Have there been any similar requests on the webtools side?

sayedihashimi commented 8 months ago

I don't think we have ever had good support for running external apps along with the project in Visual Studio. We have heard numerous requests for better support for these scenarios.

I think this is more important given the rise of Cloud Native app development. I'm adding @DamianEdwards and @bradygaster to see if they have additional comments.

DamianEdwards commented 8 months ago

Adding @javiercn who has prototyped an MSBuild->npm integration solution (https://devblogs.microsoft.com/dotnet/build-client-web-assets-for-your-razor-class-library/) in this space.

One thing to consider is that launchSettings.json isn't just for VS, but aspects of it are read by and supported by dotnet run and dotnet watch too. Anytime we think about adding properties to launch profiles we need to consider the behavior in those modalities too.

We basically have these integration points today:

Integrating watcher-type build toolchains is a bit more complicated as others have pointed out and generally speaking is difficult in modalities that don't have an obvious session semantic in their use, e.g. dotnet build and dotnet run execute and then end, whereas dotnet watch keeps running until the user terminates it. If build kicks off a watcher, careful consideration has to be given to who owns the lifetime of that process, timeouts, re-use for subsequent runs, cache invalidation, etc.

Generally speaking, I think that MSBuild is the right integration point for kicking of anything associated with processing project source files into application assets, i.e. "building" the project. All the other user interactions during the inner-loop are higher level than this (VS build/launch/debug, dotnet run/watch, etc.) so they get the benefit automatically. I really like the prototype @javiercn built for this reason.

Launch profiles are the integration point for changing aspects of the launch UX itself, e.g. setting environment variables for the launched process, whether to launch a browser or not, the verbosity of messages the launch command displays, the URL/port to launch the application at, etc. If there are scenarios where launching another executable/script is desirable only in the context of launching the project during the developer inner-loop, then extending launch profiles to support that might be useful.

labsin commented 4 months ago

I also have another user case where this would be useful.

We develop a .net plugin that is loaded by an external program. If our software is installed, it gets loaded automatically (by convention from a folder or by using a reg key that points to the location of the plugin) To debug, right now, we install our software and then override the installed files when building (only when building from VS) But this is quite messy when switching between versions using installers and debug builds from VS.

Ideally, we'd have a launch script that:

Then we don't have to overwrite any local files on build and can have a nice debug launcher.

I tried:

I don't know how other projects that use .net plugin do this.