Visual Studio: Manage debugging command line arguments for the app

夙愿已清 提交于 2021-01-29 07:50:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!