问题
Is there any simple way to manage command line arguments for C++ project (I suppose the same for C#) in Visual Studio like it works in Visual Studio Code where you have dropdown with different run presets? I'm developing CLI and need to change arguments pretty often. Now I have to copy paste them from txt file. I guess it's not the easiest way to handle this :)
UPD: Just to clarify I'm speaking about Console application project properties -> Debugging -> Command Arguments block.
回答1:
You can use the following command for Visual Commander to set command line arguments for a selected C++ startup project and start debugging:
(Language: C#, References: Microsoft.VisualStudio.VCProjectEngine)
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.VCProjectEngine;
public class C : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
Project startupProject = DTE.Solution.Item(((DTE.Solution.SolutionBuild as SolutionBuild2).StartupProjects as object[])[0]);
VCProject vcproj = startupProject.Object as VCProject;
VCConfiguration vcconfig = vcproj.ActiveConfiguration;
VCDebugSettings vcdebug = vcconfig.DebugSettings as VCDebugSettings;
vcdebug.CommandArguments = "my_arguments_1";
DTE.ExecuteCommand("Debug.Start");
}
}
Having several such commands with different arguments, you can quickly select and run them from the VCmd menu.
来源:https://stackoverflow.com/questions/53938771/visual-studio-manage-debugging-command-line-arguments-for-the-app