Wednesday, August 15, 2007
"Organize Usings" in VS code name "Orcas" ala Eclipse
Those that have used Eclipse will probably miss the ctrl+shift+o shortcut ("Organize Imports") when you switch to VS. But now VS code name "Orcas" provides a "new" feature (which unofficially existed in Whidbey) that allows you to remove and sort usings:
So if you don't want miss the Eclipse feature anymore you can add the shortcut going to Tools->Options->Environment->Keyboard
Search the RemoveAndSort command and press the ctrl+shift+o combination. Note that the shorcut is currently used by the OpenProject command and it will lost if you confirm to use the combination for the RemoveAndSort command.
Labels: .Net, Java, VS Extensibility
Sunday, August 05, 2007
GAX 1.3 is out!
This new version of GAX is a must if you are thinking to develop Guidance Packages using VS Codename "Orcas" (previous version of GAX didn't work with the latest version of VS) and it will also provide some new features if your are developing with VS 2005.
A welcomed “fix” is the enhancement of the registration process. Now it's smarter about whether to install VB templates based on the presence of VB as a Visual Studio's product. This means that if your Guidance Package contains VB templates (.vstemplates for VB projects or items) you won't need to add conditional logic in your installer to avoid the registration failure when the package is being installed or registered.
The GAX installer is also improved to use WIX technology but the GAT installer project that is unfolded when you create a new Guidance Package using GAT is still the same VS Setup Project.
At last, the Experimental Hive registration is now a built-in feature in GAX allowing you to register your Guidance Packages in both Normal and Experimental hives.
So it seems that this CTP is a necessary and welcomed update for the runtime but not for the UX of developing Guidance Packages.
Here you have the links:
- Grigory Melnik's announcement
- GAX July 2007 CTP download
- GAT July 2007 CTP download
Labels: .Net, GAX/GAT, VS Extensibility
Wednesday, April 04, 2007
.Net Generic Finder (VS Automation Model Usage)
I know there are Find/FindAll methods in the System.Collection.* namespace but what I was looking for is something quite different. Here is more or less the scenario:
Suppose you have objects that can be any of the following interfaces: Solution (S), Project (P) or ProjectItem (PI). You don't have a common super type to treat all as polymorphic objects. So if you have a collection of them (Objects) you are not able to have Collection<T> where T is { S | P | PI } because you could have a mix of them (of course at least you have a Collection<Object> but in this case we would not need Generics anyway).
I wanted a finder that allows me to search for an object in this object collection but using the benefits of Generics. I wanted to use the most abstract representation of a collection I could have and I decided to use an IEnumerable parameter. Then I needed to define a Predicate<T> and what I am going to expect is a T or IEnumerable<T> result.
For example: If the col is = { S1, P1, P2, P3, PI1, PI2, PI3 }
The following tests should pass:
1. Finder.FindAll<Solution>(col, delegate( return Predicates.GetNullPredicate<T>())) contains {S1}
2. Finder.FindAll<Project>(col, delegate( return Predicates.GetNullPredicate<T>())) contains {P1, P2, P3}
3. Finder.FindAll<ProjectItem>(col, delegate( return Predicates.GetNullPredicate<T>())) contains {PI1, PI2, PI3}
So I am able to get a IEnumerable<T> where T is { S | P | PI }. I could also specify any other predicate to evaluate specific properties of each T. Notice that I am using the Predicates.Is<T> helper method I published in my previous post to validate if the predicate can be evaluated. I am also using the yield support to collect the result.
public static class Finder
{
public static T Find<T>(IEnumerable elements, Predicate<T> predicate) where T : class
{
IEnumerator<T> enumerator = Find(elements, predicate, true).GetEnumerator();
return enumerator.MoveNext() ? enumerator.Current : null;
}
public static IEnumerable<T> FindAll<T>(IEnumerable elements, Predicate<T> predicate) where T : class
{
return Find<T>(elements, predicate, false);
}
private static IEnumerable<T> Find<T>(IEnumerable elements, Predicate<T> predicate, bool returnFirst) where T : class
{
if (null != elements)
{
foreach (object element in elements)
{
if (Predicates.Is<T>(element, predicate))
{
yield return (T)element;
if (returnFirst) yield break;
}
}
}
yield break;
}
}
Labels: .Net, VS Extensibility
Tuesday, March 13, 2007
Adding Refactor Context Menu in Visual Studio .Net Add-ins
When you are creating a new VS .Net Add-in, you can optionally add a command in the "Tools" Command Bar. But what if you want to add your add-in in another command bar? Well, I didn't find a nice way to do that. What I needed was to add the a Command in the Refactor Command Bar (Menu and Context Menu) so what I was looking is the following result:
What you need to do is to use the "MenuBar" (the same that creates the Add-In wizard for the "Tools" Command Bar) and the "Other Context Menus" (this is the one you need to add the menu in the context menu).
here it's the (simplified) code fragment:
CommandBar menuBarCommandBar = ((CommandBars)_applicationObject.CommandBars)["MenuBar"];
CommandBar otherContextMenu = ((CommandBars)_applicationObject.CommandBars)["Other Context Menus"];
CommandBarControl refactorControl = menuBarCommandBar.Controls["Refactor"];
CommandBarPopup refactorPopup = (CommandBarPopup)refactorControl;
CommandBarControl refactorContextControl = otherContextMenu.Controls["Refactor"];
CommandBarPopup refactorContextPopup = (CommandBarPopup)refactorContextControl;
What I did to discover the "Other Context Menus" CommandBar name?... well take a look at this article: HOWTO: Guessing the name of a command bar to add a custom menu entry in Visual Studio .NET add-ins
Labels: .Net, VS Extensibility
Thursday, March 08, 2007
VS Language Service with MPF/Managed Babel
A few weeks ago I started to work on a prototype language service for Visual Studio. We want to try the new Managed Babel System... so what is that? Let's start describing the scenario: Suppose you have your own language and you want to integrate it into Visual Studio providing Syntax Coloring, Statement completion, error markers, etc. The VS SDK offers the MPF (Managed Package Framework) that provides a managed "easy" way to extend Visual Studio including support for language services.
And if you want to go a step further, you also have the Managed Babel System which lets you to specify a couple a files contaning the scanner and parser deifnition using LEX/YACC like syntax and tools (MPLEX, MPPG) to generate a lot of code you need to make the language service works.
These are the resources I found useful to start using these frameworks:
- VS SDK Documentation
- VS Extra Documentation: Managed Babel Overview, MPLEX and MPPG documents included in the VisualStudioIntegration\ExtraDocumentation directory (under your VS SDK installation directory)
- ManagedMyC sample: Included in the VS SDK samples.
- The Lex & Yacc Page
- Visual Studio Extensibility Forum
-Adrian
Labels: .Net, VS Extensibility