2

I need to achieve some kind of extensibility for a custom project template.

Having a C# code file opened, if...:

  • ...current project has some specific type id.
  • ...code file is a class and inherits some concrete base class.
  • ...user pressed F5.

...I'd like to...:

  • ...start an arbitrary program (a console application).
  • ...attach Visual Studio to the process of the arbitrary program.
  • ...debug.

Actually I'm absolutely lost and I don't know how to do so. I know I need Visual Studio 2010 SDK, but I don't know how to create an extension doing what I need to achieve.

Thank you in advance.

UPDATE

I'm doing some research in Stackoverflow Q&A and I'll be adding questions related to my own one:

Community
  • 1
  • 1
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206

3 Answers3

2

I guess the best way to try is VS addin that will catch the Run (F5) command and handle it as you wish. See this article as a starting point for catching command from VS addin: How to: Add and Handle Commands. And these for attaching to process from VS addin Attach to process for lazies and Visual Studio Add-In To Automatically Attach to Development Server

Hope that helps to find a solution for your needs.

Community
  • 1
  • 1
Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121
  • It seems it can help in my goals. The hardest part of my question is **"...code file is a class and inherits some concrete base class."** This seems manipulating document window someway, but I don't know how to get class namespace, name and its base class. – Matías Fidemraizer Jun 18 '12 at 08:51
  • Read about Roslyn - maybe that is what you need to use - http://msdn.microsoft.com/en-US/roslyn – Dmitry Pavlov Jun 18 '12 at 13:31
  • Roslyn is more about compilation. – Matías Fidemraizer Jun 18 '12 at 14:41
  • Well in this case you will need to parse the C# file yourself I guess. – Dmitry Pavlov Jun 18 '12 at 15:02
  • Hope I can find some open source parser..! – Matías Fidemraizer Jun 18 '12 at 15:07
  • Sure. Look at this thread http://stackoverflow.com/questions/81406/parser-for-c-sharp – Dmitry Pavlov Jun 18 '12 at 15:18
  • DmitryPavlov I was looking at Irony parser, but NRefactory looks promising! Thank you again! – Matías Fidemraizer Jun 18 '12 at 15:51
  • You're welcome! I guess Irony will be too complex for C# grammar if you will decide to write it from scratch. Any more simple framework will be more than enough. But Irony itself is very interesting thing to play with of course. – Dmitry Pavlov Jun 18 '12 at 16:47
  • Yeah. BTW sadly I'm thinking on discarding add-in/extension development. I'm having a lot of problems, documentation is horrible and the API itself is a pain in the ass. It's incredible how a great product like Visual Studio has that horrible extensibility system... – Matías Fidemraizer Jun 18 '12 at 17:06
  • Well. You're right - sometimes not much documentation, API is not ideal. I have spent a year to figure out VSX packages area myself in 2006. VS extensibility appeared recently so that is why it still is not ideal. But now it becomes much better. The best place to find an answer is to ask it on MSDN VSX Forum [http://social.msdn.microsoft.com/Forums/en/vsx/threads] - there are a lot experts and guys from Microsoft who always ready to help. – Dmitry Pavlov Jun 19 '12 at 19:01
  • I guess you can just create an add-in and parse the file source in it (with regex or smth like that) that it is iherited from specific base class. – Dmitry Pavlov Jun 19 '12 at 19:04
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/12758/discussion-between-dmitry-pavlov-and-matias-fidemraizer) – Dmitry Pavlov Jun 19 '12 at 19:04
0

Do you consider the use of third-party extensions, for example, the free DXCore Visual Studio Extensibility Framework? It can do what you need.

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
  • Yes, I knew about it and I'm considering it, but as its a layer on top of Visual Studio extensibility and it doesn't have source code, I don't like it using it. But since there's few choice, maybe, why not? – Matías Fidemraizer Jun 18 '12 at 14:43
0

First of all, thank you everyone for the info, it has been useful.

Basically I got the way to do what I'm looking to achieve.

Because I want to assist others in a similar situation, I'd like to share what I'm using to solve everything:

  • NRefactory as C# code parser. It works like a charm! You can get a lot of info from a code file.

  • VSPackage Visual Studio 2010 SDK project template.

  • In order to attach to a process I'm going to look forward for Dmitry Pavlov's suggestions.

Interesting links:

As soon as I got everything working, I'm going to edit this answer and give more detailed info.

Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
  • Can you share how to implement custom action when F5 is pressed using VSPackage. [I'm facing such an issue](http://stackoverflow.com/questions/26113987/compilation-succeeded-even-though-there-were-some-errors-from-roslyn-diagnostic), I'll have to check the number of errors prior to compilation. – Jerric Lyns John Sep 30 '14 at 14:32
  • @JerricLynsJohn I can look for the code, but it has been a long time since I had this issue... :( – Matías Fidemraizer Sep 30 '14 at 14:54