Add-on components that enhance and customize the Visual Studio integrated development environment
Thank you for detailed explanation. This is well thought out scenario and you are not missing anything obvious. What you are trying to achieve (runtime-only configuration overrides during debugging, without touching disk or persisting state) is not directly supported by current Visual Studio extensibility model, which is why the approaches you tried are hitting limitations.
That said, here's the most accurate and recommended approach, along with clarification on why the previous attempts didn't work.
Key Limitation
A VSIX extension runs in a separate process(devenv.exe) and does not have direct control over the configuration pipeline of the debugged process (your ASP.NET Core app).
This means:
- EnvironmentVariableTarget.Process -> applies to VS process, not target app.
- User/Machine-> persists (not desired)
- launchSettings.json-> file-based ( not desired).
Recommended Approach (Supported and clean)
Use Debug Launch Customizable via DebugLaunchProvider
Instead of trying modify config after launch, you should inject environment variables at debug launch time using:
IDebugProfileLaunchTargetsProvider (modern approach)
This is the correct extensibility point for .NET Core / ASP.NET Core projects.
What this gives you:
- Runtime-only overrides
- No file system changes
- Scoped to debug session
- Works with ASP.NET Core config system (IConfiguration)
Implementation Outline
- Create a VSIX extension
- Export a custom launch provider:
[Export(typeof(IDebugProfileLaunchTargetProvider))] [AppliesTo(ProjectCapability.DotNetCore)] public class CustomLaunchProvider : IDebugProfileLaunchTargetsProvider { public Task<IReadOnlyList<IDebugLaunchSettings>> QueryDebugTargetsAsync( DebugLaunchOptions launchOptions, ILaunchProfile profile) { var settings = new DebugLaunchSettings(launchOptions) { LaunchOperations = DebugLaunchOperation.CreateProcess, Executable = profile.ExecutablePath, Arguments = profile.CommandLineArgs, CurrentDirectory = profile.WorkingDirectory }; //Inject environment variable here settings.Environment["MaintenanceConfiguration__MaintenanceWindowCheckEnabled'] = "false"; return Task.FromResult<IReadOnlyList<IDebugLauncgSettings>>( new[] {settings}); } }
Important notes
- Use __(double underscore) for nested config keys in ASP.NET Core.
- These values will be picked up automatically via: IConfiguration[
"MaintenanceConfiguration__MaintenanceWindowCheckEnabled'] = "false"; - This only applies during debugging, exactly matching your requirement
Alternative (if you need more control)
if you need even more flexibility (e.g., per-project overrides in multi-project solutions):
- Implement a custom configuration provider in your app.
- Read values from a temporary in-memory source (e.g., named pipe, local service, etc.)
But this require app-level changes, whereas the above VSIX approach does not.
Please try the steps shared above and let me know if this resolves the issue.
If it works, you may mark this reply as the Accepted Answer — this helps other customers with similar questions find the solution faster.