locked
Visual Studio 2010 Add-In Question RRS feed

  • Question

  • I am trying to create an Add-In for Visual Studio 2010.  Eleven months ago, I created an App Wizard written in HTML, CSS and JScript that works quite well.  It creates whole applications.  I want my Add-In to add classes to existing projects.

    In the template files of the app wizard there are many dictionary substitution items of the form "[!output DICT_ENTRY]" where DICT_ENTRY is a placeholder for an actual dictionary entry, like "APP_NAME" for example.

    Is there a way that I can include template files for the classes I want to make available to the Add-In that employ the same dictionary substitution syntax employed by the App Wizard?

    I would like to incorporate the template files inside of the Add-In dll as resource files, like I am able to do in Visual Studio 6.0.  It is so easy to do things in Visual Studio 6.0 that seem quite difficult in Visual Studio 2010 and, of course, in Visual Studio 2012 RC (or is it Beta? ... I can't remember).

    Before you go asking me why I don't just stick with Visual C++ 6.0, let me just say that I finally had to upgrade from Windows 2000 to Windows 7 and I would like access to some of the newer API's available in Windows 7.

    Hence, the need for Visual Studio 2010.  By the way, I don't like the way Visual Studio 2012 looks.  It's a bit dark, is it not?  It looks like it was designed by Darth Vader's younger cousin, you know, the one with brain syphilis.

    Anyway, back to the Add-In question.  Is there an engine I can use that will perform the substitution in my templates, or do I have to write the routine myself? - Thanks for any light you may be able to shed on this 'dark' topic.

    Update a little later in the day:

    The fun just never ends.  I tried to embed two template files in a .resx file.  Guess what?  Even that simple task gets totally screwed up by VS 2010!  Not only does Visual Studio 2010 refuse to save the content of templates in the .resx file, saving a reference to the filename, instead, but it goes one better: It doesn't even remember the location of the file and fails to find it when I try to reference it in code!!!  This is truly incredible.  The guys at Microsoft must stay up late every night just trying to figure out new ways to sabotage the efforts of honest developers.  If that's not their intention, then they're doing a really 'great' imitation of someone with that intention.

    If I seem a little nasty, it's only because of the nastiness of the product that I am trying to use here to some constructive end.


    Monday, July 9, 2012 2:24 PM

Answers

  • Hi Charles,

    Add-ins and templates and two very different creatures.

    What you describe (adding classes to existing projects), is achieved by writing an item template. If you are targeting C++ projects, then you would use the older .vsz/IDTWizard based templates(where you can use the existing C++ Wizard engine). If you are targeting something like C# or VB .NET, you would use the newer .zip/.vstemplate based scenario.

    Once you have the item template working (invocable via the "Add New Item" dialog), it's just a matter of your add-in calling ProjectItems.AddFromTemplate. The documentation is certainly convoluted around this. If you can provide some additional details around which sort of project types(s) your targeting here, and what kind of code you're interested in adding, we can probably provide some additional pointers.

    Answer to #2: You don't. Unless you want to do all the work yourself (copy files, and programatically add them to the project). In that case, you would embedd the file(s) as a resource, and access them as described in the following KB article:

       How to embed and access resources by using Visual C#.

    Sincerely,


    Ed Dore

    Tuesday, July 10, 2012 6:16 PM

All replies

  • Hi Charles,

    I am confused by your issue. I can't find your purpose clearly.

    I guess you want to add a project item to current projects via add-in.

    You can use ProjectItems.AddFromTemplate.

    If I misunderstand your meaning, please feel free to let me know.

    Best regards,

    Disley

    Tuesday, July 10, 2012 7:28 AM
  • Hi Disley,

    I don't believe ProjectItems.AddFromTemplate is what I need.  I don't know what it does.  Certainly the documentation doesn't provide the smallest clue.  If I already knew what ProjectItems.AddFromTemplate did, then I wouldn't need documentation, would I?  But not already knowing what it does, I would need to obtain this information before using it.  That information is lacking in the documentation.

    I am trying to learn how to do two things:

    (1) Is there class/interface/whatever that will perform a dictionary based substitution as I described in my thread, above.  If not, I'll write the routine myself.  It wouldn't be the first time.

    (2) How do I store my template files as a resource in the dll, in the C# based Add-In?  One can easily do this with classic resource (.rc) files.  Trying to do this with .resx files doesn't seem to work as I described, above.

    This is the first time I've ever written an actual application using C#.  I am a C++ programmer.  I know how to use .rc files.  I could change to a C++ application, but I decided to try writing the stupid thing using C# and .NET, because, evidently, I am a masochist.

    Thanks for responding, Disley.


    Charles S. Cotton

    Tuesday, July 10, 2012 1:14 PM
  • Hi Charles,

    Add-ins and templates and two very different creatures.

    What you describe (adding classes to existing projects), is achieved by writing an item template. If you are targeting C++ projects, then you would use the older .vsz/IDTWizard based templates(where you can use the existing C++ Wizard engine). If you are targeting something like C# or VB .NET, you would use the newer .zip/.vstemplate based scenario.

    Once you have the item template working (invocable via the "Add New Item" dialog), it's just a matter of your add-in calling ProjectItems.AddFromTemplate. The documentation is certainly convoluted around this. If you can provide some additional details around which sort of project types(s) your targeting here, and what kind of code you're interested in adding, we can probably provide some additional pointers.

    Answer to #2: You don't. Unless you want to do all the work yourself (copy files, and programatically add them to the project). In that case, you would embedd the file(s) as a resource, and access them as described in the following KB article:

       How to embed and access resources by using Visual C#.

    Sincerely,


    Ed Dore

    Tuesday, July 10, 2012 6:16 PM
  • Hi Ed,

    Thank you for your very helpful response.

    Actually, today I went ahead and wrote my own TemplateServices class implementing a dictionary and a template substitute function.  It works perfectly!  I've done this inside of a Visual Studio 2010 add-in.  I used C# because I thought I'd try something new.  I've put off wading in the .NET C#/VB/Structured C++ pool until now.  Actually the .NET framework seems fairly mature and I had only a very few snags, none of which took much effort to overcome. 

    A notable snag was trying to figure out how to get a byte[] array assigned to a string object.  I couldn't figure out how to do it with a cast and had to first copy the byte[] array into a char[] array.  It was then an easy matter to get it into the string: string str = new string[cp].  Oddly, there isn't an overload for: string str = new string[bp] (where cp is a char array and bp is a byte array).

    In C/C++ with pointers, this would not be a problem.  I don't like not being able to delete items that I've new'd.  Hopefully, the .NET internal, automatic deallocation routines are competently written.  I consider this to be a sloppiness and an imbalance that does not exist in C++.  Nanny state coding wants to take care of me when I want to take care of myself.  Also not being able to "#define MY_PREPROCESSOR_IDENTIFIER 16" seems like an oversight in the design of C#, as well as ItemData missing from the ComboBox that is part of Windows Forms.  Oops.  I know, I know:  It is "by design" which means 'by oversight which we'll call by design' It's a good thing Microsoft doesn't build automobiles because the missing 'reverse gear' would get promoted to a feature 'put in by design' (not being able to put the car in reverse) !

    My projects are all C++ Desktop applications, mostly business database applications using SQL Server, MS Access and MySQL (I had to write my own OLEDB provider for MySQL because the ODBC OleDB provider does not support bookmarks which my applications require.

    These apps are based upon my own two frameworks, (1) wfc (Windows Foundation classes, based upon MFC, which I pulled apart and put back together, resulting in a much more rational and comprehensible implementation that is also MUCH LESS FRAGMENTED than MFC and (2) dfc (Database Framework Classes) which is a comprehensive collection of classes that wrap OleDB inside of a DAO like interface.  Yes, that's right, DAO.  I've been doing this for a while.  I link to these two frameworks as static library (.lib) files.

    I realize that this is probably much more information than you wanted, but you asked...

    I'll look at the article you referenced regarding embedding text files in the manifest tomorrow morning.

    Thanks again for your help.


    Charles S. Cotton

    Wednesday, July 11, 2012 5:08 AM