5

How do I add a custom "Run/Debug in X" command to Visual Studio 2012?

I have a C#/.NET application, let's call it "X," that supports loadable plugins. To write a plugin, I create a new C# Class Library project in Visual Studio, reference a certain assembly, and write my code. To test the plugin, I need to copy the compiled plugin DLL to a particular runtime directory, write an XML configuration file, and run X. I can automate some of this using a Post-Build Event and the project's Debug properties ("Start external program").

But what I really want is to click Debug and then click a custom "Run in X" (or "Debug in X") command that invokes some kind of plugin or script to do all of this. The script will handle creating an X config file, runtime directory, copying the DLL, launching the X application and attaching the debugger to it.

I'm willing to write a Visual Studio plugin to accomplish this, but don't really know where to start.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
TypeIA
  • 16,916
  • 1
  • 38
  • 52

2 Answers2

0

The easiest way I can think of to do this is to configure your Debug build to run a PowerShell post-build event and launch the application externally.

Make a "Debug.ps1" file in your project and set it to BuildAction=Content, Copy=Copy Always. Script out your debugging prerequisites here.

Get-ChildItem | Copy-Item -Destination C:\ExternalApp\Plugins -Force
#build config, etc here

Call this in your Debug post-build events C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File Debug.ps1

Hit F5, and your external app will launch with the latest copy of your plugin loaded and debugger attached.

Jon Tirjan
  • 3,556
  • 2
  • 16
  • 24
0
  • Write a T4 template that does all the heavy lifting (creating the config file, directory, moving the dll, and starting X)

  • Refer to this answer for how to run the template on each build. Set this up as a post build event

  • Build -> Attach to X

If you go this route, I would recommend the EnityFramework's default tempaltes as a tutorial for what you want to accomplish. They use a utility template, with classes that demonstrate how to leverage C# to generate and modify a file. From there it is trivial check if a file exists, move a file, or even start X (Process.Start("X.exe");).

You can find those default EF templates at %ProgramFiles(x86)%\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\.

Community
  • 1
  • 1
Eric Lease
  • 4,114
  • 1
  • 29
  • 45