Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alex-jitbit opened this issue Dec 28, 2023 · 6 comments
Open
Labels
Feature-Debugging Launching an application via F5, setting debug properties and launch profiles. Triage-Investigate Reviewed and investigation needed by dev team
Milestone

Comments

@alex-jitbit
Copy link

alex-jitbit commented Dec 28, 2023

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:

  • 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
  • etc. etc.

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
Copy link

ViIvanov commented Dec 28, 2023

  • 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
Copy link
Author

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

@tmeschter tmeschter added Feature Request Feature-Debugging Launching an application via F5, setting debug properties and launch profiles. labels Jan 11, 2024
@tmeschter tmeschter added this to the Backlog milestone Jan 11, 2024
@kvenkatrajan
Copy link
Member

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

@sayedihashimi
Copy link
Member

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
Copy link
Member

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:

  • MSBuild (targets brought in my the project file and/or referenced SDKs)
  • Launch profiles (launchSettings.json, with behavior actually implemented in the launch host, e.g. VS, dotnet run, dotnet watch, etc.)
  • Directly in the IDE (e.g. selecting which browser to launch is only supported in Visual Studio directly)

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.

@drewnoakes drewnoakes added the Triage-Investigate Reviewed and investigation needed by dev team label Jan 18, 2024
@labsin
Copy link

labsin commented Jun 5, 2024

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:

  • Launches the external software
  • Instructs it to load our plugin from the build output location
  • Have a way to instruct the debugger to debug the pid of the launched external software

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

I tried:

  • a wrapper executable/script that does the above steps, but the VS debugger doesn't debug child processes spawned.
  • this wrapper/script, but always run it without debugger and then have the plugin do Debugger.Launch when some env-variable is set (in launchSettings.json). This works, but it would be nicer if there was a more streamlined way so I don't have to select the correct VS instance, press ok, press continue debugging in VS, every time I debug and that I can just use the Run and Debug functionality in VS.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature-Debugging Launching an application via F5, setting debug properties and launch profiles. Triage-Investigate Reviewed and investigation needed by dev team
Projects
None yet
Development

No branches or pull requests

8 participants