Add-on components that enhance and customize the Visual Studio integrated development environment
Thank you for reaching out. Please find the answer below.
Correct Way to Inject Environment Variables into .NET Framework Debug Launches
Why IVsDebugLaunchTargetProvider2 Doesn’t Work
That interface is only used by the generic launcher (CMake, Open Folder, launch.vs.json projects).
Classic .NET Framework (.csproj) projects bypass it entirely and call the Managed debug engine directly.
So, your SetupDebugTargetInfo will never fire, no matter what DebuggerTemplate string you try.
The Two Supported Approaches
Option A: Implement a Launch Settings Provider
For projects that use CPS (including some managed projects in newer VS SDKs), you can hook into debug launch by implementing IVsDebugLaunchSettingsProvider:
[Export(typeof(IVsDebugLaunchSettingsProvider))]
[AppliesTo(ProjectCapability.CSharp)] // scope to C# projects
public class EnvVarLaunchSettingsProvider : IVsDebugLaunchSettingsProvider
{
public Task> GetLaunchSettingsAsync(DebugLaunchOptions launchOptions)
{
var settings = new DebugLaunchSettings(launchOptions)
{
Environment = new Dictionary
{
{ "MYFLAG", "1" },
{ "FOO", "BAR" }
}
};
return Task.FromResult>(new[] { settings });
}
}
Visual Studio will merge these into the process environment before launching.
Option B: Modify the Debug Tab’s Environment Property
Every .NET Framework project already has a Debug property called Environment (visible in Project Properties → Debug).
You can programmatically set this from your extension:
var dte = (DTE2)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
var proj = dte.Solution?.Projects?.Item(1); // your startup project
var config = proj.ConfigurationManager.ActiveConfiguration;
// Set environment variables (semicolon-separated)
Visual Studio automatically merges these into the debugged process’ environment.
Debugging & Testing Your Extension
- Run Visual Studio with
/rootsuffix Expto start an experimental instance. - Attach to
devenv.exeand put breakpoints in your provider/property code. - Press F5 on a .NET Framework app and verify your environment variables appear.
Bottom Line
- Use
IVsDebugLaunchSettingsProviderif you want to inject dynamically at launch. - Use the project’s Environment property if you want a persistent, configuration-based approach.
- Don’t waste time trying to guess a
DebuggerTemplate— it’s not used for .NET Framework.csprojdebugging.
Let us know if you need further help with this. We'll be happy to assist.