Visual Studio Extensions and Menu Subitems

Recently I was working on a Visual Studio Extension for VS2010, instead of a single item in the the tools menu, what I wanted was a single item with a set of child items.

Strangely enough, documentation on this is quite lacking. So if you need to know how to do it, here’s the gist. First, create a standard Visual Studio 2010 extension with the wizard, we’ll have some code like the below to start off with, in the OnConnection function:

object []contextGUIDS = new object[] { };
Commands2 commands = (Commands2)_applicationObject.Commands;
string toolsMenuName = "Tools";

//Place the command on the tools menu.
//Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

//Find the Tools command bar on the MenuBar command bar:
CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;

//This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
//  just make sure you also update the QueryStatus/Exec method to include the new command names.
try
{
	//Add a command to the Commands collection:
    Command command = commands.AddNamedCommand2(_addInInstance, "MyCommand", "MyCommand",
        "Executes the command for MyCommand", true, 59, ref contextGUIDS,
        (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
        (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

   	//Add a control for the command to the tools menu:
	if((command != null) && (toolsPopup != null))
	{
		command.AddControl(toolsPopup.CommandBar, 1);
	}
}
catch(System.ArgumentException)
{
	//If we are here, then the exception is probably because a command with that name
	//  already exists. If so there is no need to recreate the command and we can
    //  safely ignore the exception.
}

Now what we’re going to do first, is change the code so that we don’t actually add a Command named MyCommand, but instead a popup:

//This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
//  just make sure you also update the QueryStatus/Exec method to include the new command names.
try
{
	//  Have we got the tools popup?
	if(toolsPopup != null)
	{
        //  Create 'MyCommand' as a popup.
        var popup = (CommandBarPopup)toolsPopup.Controls.Add(MsoControlType.msoControlPopup);
        popup.Caption = "MyCommand";
	}
}
catch(System.ArgumentException)
{
	//If we are here, then the exception is probably because a command with that name<br />
	//  already exists. If so there is no need to recreate the command and we can<br />
    //  safely ignore the exception.
}

Now that we have the popup object, we can create commands and add them to the popup instead:

//  Have we got the tools popup?
if(toolsPopup != null)
{
    //  Create 'MyCommand' as a popup.
    var popup = (CommandBarPopup)toolsPopup.Controls.Add(MsoControlType.msoControlPopup);
    popup.Caption = "MyCommand";
    //  Create sub item 1.
    var subItem1Command = commands.AddNamedCommand2(_addInInstance, "MyCommand1", "My Command Subitem 1", "My Command Subitem 1",
                                                       true, 59, ref contextGUIDS);
    //  Add it.
    subItem1Command.AddControl(popup.CommandBar, 1);
    //  Create sub item 2.
    var subItem2Command = commands.AddNamedCommand2(_addInInstance, "MyCommand2", "My Command Subitem 2", "My Command Subitem 2",
                                                       true, 59, ref contextGUIDS);
    //  Add it.
    subItem2Command.AddControl(popup.CommandBar, 2);
}

Now that we have made these changes, if we run the addin, we get a menu structure like this:

XPath Studio – First Cut

I have just uploaded the first cut of my mini-project ‘XPath Studio’. This project is a small site that lets you choose a URL to a source webpage, and run any XPath query against it – showing the data that is returned from the query.

At the moment this blog has an issue with images so I cannot upload screenshots, but in the next few days they’ll be there. Until then, you can try out XPath Studio by visiting:

www.xpathstudio.com

The project is ASP .NET MVC 4, with Razor. I’ve stripped out the bulk of the styling that’s provided by default, and layed it out with Twitter Bootstrap.

This is the first time that I’ve used Bootstrap and already have decided that it’ll be my first choice for web applications, at least those in the proof of concept phase. The library is lightweight, easy to use, clean and simple.

More updates on XPath Studio will come over the next few days, as I tweak the core functionality based on feedback.

Deployment Projects in Visual Studio 2012

As part of Microsoft’s ongoing campaign to reduce the usability of their tools for anyone who isn’t working in exactly the way they want, Visual Studio 2012 no longer comes with the ability to create setup and deployment projects.

This is a pretty serious change. For anyone who is developing client applications, then an installer is pretty critical. Now the feature set in the VS deployment projects was fairly small – they were aimed towards making pretty basic, lean installers. And that was fine. That was what we needed it for. Installers for utility apps, installers for basic client applications, installers for testing out projects on other machines before we went to more advanced systems.

What’s truly disappointing is the lack of alternatives. Rather suspiciously there are links to InstallShield projects in Visual Studio now.

If you’ve never worked with InstallShield before then I envy you. It is truly awful – a maintainance nightmare combined with a user interface that makes creating basic installers baffling.

So Visual Studio now has no deployment projects. You can try using the free edition of InstallShield, but be ready for a world of pain. Also, considering the vast complexity of the UI, the free edition is incredibly limited in functionality – for example you cannot create ‘features’ (i.e. the chunks of functionality that you offer as an optional feature for an installation).

Example of Time Wasted

My Switch addin for Visual Studio adds a button to the UI that lets you switch between related files (cpp/h, aspx/aspx.cs etc etc).

I need to update it to work in Visual Studio 2012. I cannot develop VS 2012 addin projects in Visual Studio 2010. With a sigh I move the solution into 2012. I write the 2012 addin. The deployment project doesn’t load (as expected). I build the binaries into specific locations. I open the project in 2010. The 2012 addin doesn’t load (as expected). However, the setup project will not build due to an error when ‘updating dependencies’. This project has no dependencies – it builds from specific locations.

So now to release a version of Switch that supports VS2012, I need to use InstallShield. InstallShield’s free edition doesn’t support features – therefore I have to install Switch for 2008, 2010 and 2012 for everyone, always, regardless of whether they have it. A two hour update is not looking possible now. I don’t have the time to waste trying to bring back functionality I already had and have to move onto other work.

Conclusion

Thanks MS for removing this critical feature, and replacing it with an essentially useless and overly complicated alternative.

Please remember, we’ve paid for Visual Studio – not for a vessel to host adverts to other products. We had the functionality before, now its gone – replaced by links to an expensive (and frankly crap) suite of tools that aren’t suitable. Why has this happened? The cynical part of me thinks there’s some kind of deal going on between MS and InstallShield (well of course there is), and we’re suffering from it.

Hit the uservoice page here: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/3041773-bring-back-the-basic-setup-and-deployment-project- to try and vote for it to go back in.

 

Goodbye BlogEngine.NET, Hello WordPress

I run my websites on a Windows Server. Years ago, when I started web development, I ran almost exclusively on LAMP (Linux, Apache, MySQL, PHP) setups, which worked great for the sites I was building.

As I got more involved in commercial development, most of the sites and services I was working on were C#, ASP, IIS and MSSQL Server focused. This is great for web development too.

When I moved onto a new, Windows based server, I decided that as I was running MSSQL Server and IIS on it, I would move my personal blog onto an ASP based platform – for this I chose BlogEngine.NET.

More than one year later, I’ve moved to WordPress if you’re running sites that need some kind of content management system, it really is one of the best. With lots of support online, regular updates, plugins and themes, a WordPress site generally is easier to maintain and keep looking good than, for example, a BlogEngine .NET site.

I’ve also been very impressed with how easy it is to integrate WordPress into existing sites I’m updating my site http://www.childrenshomesnepal.org to have a news section driven by WordPress and it’s a breeze – just a little bit of PHP and the posts are there.

The short message, so far I’m yet to see a better CMS than WordPress for day-to-day use. And that includes Drupal, which is powerful, but a bit of a nightmare to set up (and requires too much IT expertise from contributors to a site).

The GAC Manager

I have started a new project on CodePlex called ‘GAC Manager’. This is a project that is in two parts, the first is a simple tool to allow users to manipulate their local global assembly cache, the second is an API that provides the core functionality.

Here’s a screenshot of the tool in its current state:

An article on the project is available on the CodeProject at: http://www.codeproject.com/Articles/430568/A-GAC-Manager-Utility-and-API

The project itself is at: https://gacmanager.codeplex.com/

As always, comments, feature requests and so on are welcome!

Changing Merge/Compare Tools in TFS

Moving from SVN to TFS has been an interesting experience. The integration of source control directly into Visual Studio seems like a good thing, but even on a well set up network it can occasionally bring Visual Studio to its knees. And I still don’t trust its automerge.

Anyway, if you find that the TFS diff and merge tools are just too ugly and odd to work with, there’s a great page on the MSDN blogs that describes how to set Visual Studio to use your preferred tool:

http://blogs.msdn.com/b/jmanning/archive/2006/02/20/diff-merge-configuration-in-team-foundation-common-command-and-argument-values.aspx

Welcome back TortoiseMerge, I’ve missed you.

Go Offline Extension for Visual Studio 2010

Such a useful extension that I just had to big it up – the Go Offline extension adds the following menu item:

File>Source Control>Go Offline

http://visualstudiogallery.msdn.microsoft.com/425f09d8-d070-4ab1-84c1-68fa326190f4?SRC=Home

If you use TFS in a big environment, sometimes this can save a stack of time. Thanks to Bernhard Tschirren for taking the time to write this and share it!

Samsung to develop software in-house

While the mobile phone market has long been based upon continuing hardware development, things are now changing and companies are having to keep up. The focus of the smartphone market is now moving towards software, rather than hardware and Samsung are taking note of this change. The South Korean technology company have decided to increase their game in order to be able to successfully compete with American technology giant, Apple. To do this, Samsung need to alter the way they create their products, by developing their own software as well as hardware. 

Samsung have begun to recruit software engineers, mostly in India, with the intention of being able to start developing their own software and thus staying at the top of the market. While many people consume data through Apple products, such as talking to business customers on their iPhones or playing partycasino.com on their Mac computers, Samsung still have a good share of the mobile phone market. They are hoping that they will be able to create software to compete successfully with the iPhone, which is known for always being ahead of the game. 

This move by Samsung to not only develop their own hardware, but their own software as well is a positive one for the company. They have announced that they are now open to mergers, as they are looking to combine with high-quality research and development companies. 

The fact that Samsung’s own software ‘Bada’ has failed to become popular by consumers in the past, means that they have been running most of their devices on Google’s Android. Their plan now is to continue with this arrangement as well as working with several other software types and developing their own in the future. After Samsung overtook Nokia as leading phone manufacturer, their confidence no doubt increased and these new developments are only set to raise their prominence in the smartphone market.