Search code examples
visual-studiovisual-studio-extensionsvs-extensibility

How can I extend Visual Studio 2017 to create a custom "start" target?


In IntelliJ IDEA, it is possible to create various different task runner configurations out of the box:

Screenshot of IntelliJ IDEA's UI

In Visual Studio, the Start button is simultaneously a drop-down menu which would to my eye suggest that it is possible to configure it to launch a custom task. For example, when working with class libraries, attempting to run the project simply shows a popup saying that class libraries cannot be started directly. I would like to have it execute some C# code instead.

Screenshot of Visual Studio 2017's UI

Can the Start button of the standard toolbar be extended to support custom launch targets?


Solution

  • According to the document of IVsDebuggableProjectCfg Interface and, IVsDebuggableProjectCfg is an optional interface implemented on the configuration object with IVsCfg and IVsProjectCfg. And the IVsProjectCfg Interface provides access to project configuration information.

    It means the "Start" target tool reads the project configure information to determine which target Visual Studio will debug.

    So you just need to change the Project configuration to set the debug target. Please change the project configuration with following steps.

    Right-Click project (Class Library) -> Properties -> Debug tab -> Start action -> Start external program (the tool/program that used to call your class library) -> Browser to choose the tool/program -> Save -> F5 (Click the Start menu). enter image description here

    It will start your class library based on your project configuration to run the tool/program that used to call your class library.