.NET Forum / Visual Studio.NET / Extensibility / February 2005
Question on usage of IVsProject::AddItem
|
|
Thread rating:  |
Notre Poubelle - 16 Feb 2005 18:09 GMT I am trying to enhance the sample MyProject managed project sample included in the VSIP 2005 Beta 1 SDK. I would like to programatically add new items to the solution explorer. It seems like the IVsProject::AddItem method is the way to go. I am confused by the second to last parameter, hwndDlgOwner. This is described in the VSIP documentation as the '[in] Handle to the Add Item dialog box'. Where would I obtain this handle from?
I looked at the unmanaged VSIP project sample, BscPrj, and I see that CMyProjectHierarchy implements the IVsProject interface and in doing so provides an implementation of AddItem. When I debug the BscPrj sample, and add an item (using the context menu in the solution explorer), my breakpoint in CMyProjectHierarchy::AddItem is called. The development environment passes in the various method parameters, including the handle to the add item dialog box. So maybe this is the answer to my first question- where do I get the handle from; it is from the development environment.
So maybe my questions now becomes, how do I add an item to the project hierarachy, if not using IVsProject::AddItem? (Any answer, whether it is in context of the managed samples or unmanaged C++ is appreciated).
"Ed Dore [MSFT]" - 16 Feb 2005 20:49 GMT I think your last question is probably steering you in the right direction here. :-)
The IVsProject::AddItem is used by the IDE via the File.AddNewItem command which displays the Add Item Wizard for example.
A project system has to implement this interface, but I haven't actually seen an instance where you'd call it to add a new item to your project. Generally speaking, if the project system/hierarchy wants to add items to itself, it would just add/insert the additional hierarchy item to it's hierarchy, and then notify the IDE by firing an IVsHierarchyEvents::OnItemAdded event.
If by chance you are just interested in adding an existing source file to your project, you would use the DTE automation model. Such as the Solution.AddFromFile or Project.ProjectItems.AddFromFileCopy() or some such.
If you have a specific scenario in mind that this doesn't address, feel free to post a bit more details about the behavior you are trying to implement.
Sincerely, Ed Dore [MSFT]
This post is 'AS IS' with no warranties, and confers no rights.
Notre Poubelle - 16 Feb 2005 21:47 GMT Thanks Ed. So, it sounds like I should abandon the IVsProject::AddItem approach. As mentioned earlier in the post, I'm trying to enhance a project system. Is the recommended approach to use the DTE automation model to do tasks like adding items (files and folders), even when working with a project system? My naive guess would've been that there would be some VSIP specific interfaces that would be preferred to the automation ones, but perhaps there is not. (I admit to being very new to this.)
You mentioned in your post that '.. if the project system/hierarchy wants to add items to itself, it would just add/insert the additional hierarchy item to it's hierarchy.. '. Are you referring to using the DTE automation model here?
"Ed Dore [MSFT]" - 16 Feb 2005 22:17 GMT That would be my initial recommendation. But then, not knowning more details about what you mean by "enhancing a project system", I'm still in the dark :-)
Note, there are some instances where it just makes more sense to use the DTE automation functionality to do certain things from within a VSIP package. In many cases (but not all) you can probably figure out a way to do the same thing via VSIP interfaces. But in instances where you can leverage the DTE automation functionality, it's probably going to be easier to implement. And there are a few things that you can do via automation (though now I can't think of anything off the top of my head), that cannot be done via VSIP.
With respect to inserting additional items into a hierarchy, this is not related to the DTE automation model. If you get a chance to implement a hierarchy (like the BscPrj sample does, via that HierUtil7 library), you'll see that each node contains properties like parentItem, NextSibling, PreviousSibling, etc, that dictates where the item resides in the hierarchy.
When you dig into that BscPrj sample, you'll see a number of "nodes" (like CFileVwFileNode) that are ultimately derived from classes in that HierUtil7 library. These "nodes" make up the items in the hierarchy. If you are the hierarchy implementor, it's your implementation that dictates what nodes are present in the hierarchy, and how they are linked together. In a project system, you'll have container nodes (nodes that contain other nodes) and item nodes that will represent the components of your project.
Aside from some of the top level container nodes, you typically let the user determine what's in the project. But lets say you want an "Other Files" folder in addition to the "References", "Source Files", "Header Files", or "Resource Files" folders you see in a typical C++ or C# project. In this instance you would simply create a new node and integrate it into your custom hierarchy. The only good examples currently available are those C++ VSIP package samples like Figs and BscPrj.
I suspect we'll have some C# samples when the VSIP SDK for Whidbey ships, as there is a lot of work going on to help better facilitate implementing custom projects with managed code.
But then again, if all you're attempting to do is add an item to the project that is already supported by the project (say a source file, for example), then I'd definitely recommend going the DTE automation route.
Sincerely, Ed Dore [MSFT]
This post is 'AS IS' with no warranties, and confers no rights.
Notre Poubelle - 16 Feb 2005 23:09 GMT Thanks for the very detailed reply Ed! I know my 'enhancing a project system' comment is rather vague. I work for an ISV and I don't want to give away too many ideas to our competitors. More importantly, I'm very much in investigation mode right now, trying to wrap my mind around what is possible with automation vs. VSIP for extending Visual Studio. Potentially we're looking to do quite a deep integration with VS. We will likely want to have our own hierarchy as we'll want several custom folders and I imagine we'll want to restrict what appears in each category.
I clearly have a lot to learn. It sounds like the massive (and daunting) BscPrj is the best starting point. From it I can learn how to define my own hierarchy, and specify the relationship between items in the heirarchy. As you noted, the HierUtil7 project implements *a lot* of the project functionality and according to the VSIP docs, it's a suggested starting point for starting creating a new project type. As this is all in C++, I'm not sure how much I'll be able to use it in the managed world, except as a model of how to implement a hierarchy. I don't suppose you know whether MS will create a managed HierUtil project do you? Also, what is the recommended approach for customizing a hierarchy based on HierUtil7 - subclass the various classes in HierUtil7 and override methods or is the implementer of the new project type expected to change the source code of HierUtil7 directly if, say, they want to specify custom folders and items and how these items exist in the hierarchy?
Ed Dore [MSFT] - 17 Feb 2005 03:28 GMT Hi Notre,
If you're looking to target VS 2005 (aka Whidbey), you'll have a much easier time implemented a managed project system. The "managed package framework" the VSIP team has been working on is going to make this a "lot" easier on you.
BscPrj is definitely a good starting point. Unfortunately, there isn't much in the way of managed project systems out in the real world. There are a couple of known problems in the VS 2003 IDE that prevent propogation of properties for items selected in a managed project system. The VSIP SDK documentation (after installing the VSIP Extras stuff) briefly alludes to this (though without the details). These problems have been corrected for VS 2005, but to avoid them in VS 2003, you should probably stick with a C++ implementation for your hierarchy implementation.
That HierUtil7 library is actually based on the same code we use for the various MS project systems. It's not quite the same, but they are very similar. It's pretty reusable. Both the BscPrj and Figs VSIP samples use it. You can probably use it "as is", and just create the various hierarchy items you wish to support. But if you need to, there's nothing stopping you from rebuilding HierUtil7. Though you may want to rename it.
Sincerely, Ed Dore [MSFT]
This post is 'AS IS' with no warranties, and confers no rights.
Notre Poubelle - 17 Feb 2005 16:57 GMT We will be looking to target Whidbey exclusively, so MPF support will be much appreciated. Thanks for all your help.
Dmitry Shaporenkov - 17 Feb 2005 11:54 GMT Hello Ed,
I remember one such thing: I didn't find any way to add a project or assembly reference to a C# project using VSIP. DTE has a VSProject.References.Add method for doing that. Sorry for an off-topic discussion but it seems somewhat related to the original post, and I'd like to learn a VSIP way for adding references, if any exists.
Thanks.
Regards, Dmitry Shaporenkov
> And there are a few things that you can do > via automation (though now I can't think of anything off the top of my > head), that cannot be done via VSIP. Ed Dore [MSFT] - 19 Feb 2005 05:40 GMT Hi Dmitry,
That looks to be like one of those situations where you can't get there with VSIP. Though you should be able to query for the DTE service and use the automation model to do it.
Each project system is implemented differently. (well, there are some common underlying C++ classes our languages use, similar to the HierUtil7 stuff). But unless you are the implementor of the hieararchy and have explicit access to it's internal workings (or expose something in addition to the prerequisite interfaces), there doesn't appear to be a way to do this via VSIP interfaces.
Sincerely, Ed Dore [MSFT]
This post is 'AS IS' with no warranties, and confers no rights.
Dmitry Shaporenkov - 21 Feb 2005 14:28 GMT Hi Ed,
thank you for your clarification. I've already left hope to do all in VSIP, but I needed a confirmation that that is impossible.
Regards, Dmitry Shaporenkov
> That looks to be like one of those situations where you can't get > there with VSIP. Though you should be able to query for the DTE [quoted text clipped - 10 lines] > Ed Dore [MSFT] > This post is 'AS IS' with no warranties, and confers no rights.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|