When does software developers perform better?

Targeting an extension for VS2010 and VS2012 using a single manifest

Hi VS coders!

Today I want to share our experience on targeting extensions to Visual Studio 2010 and 2012 in the same package.

What do we achieve with this?

  • A single .vsixmanifest file.
  • A single extension Id
  • Publish your extension in a single page of the Visual Studio Gallery

One side effect is that at the end of the migration, you must use Visual Studio 2012. We investigated possible ways to create a version of the solution to be compatible with 2010 as well, in our case, it was not possible for reasons I will describe later.

Ok, too much introduction! let’s go to the first step:

1. Changes in the vsixmanifest file:

When you first open your solution created in VS2010 in VS2012, it will try to migrate the extension project. Some interesting thing I’ve learned here:

  • The .sln file is compatible for both Visual Studio versions.
  • There is a new version of the vsixmanifest schema, but the migration process won’t attempt to migrate it (that is good because we want our extension to be backward compatible). This is the reason why after the migration, VS2012 can’t open the file with the editor, instead it directly shows you the xml.

Ok, so, in order to let your extension be able to detect VS2012 you have to add this lines in the manifest.

<VisualStudio Version="11.0">
<Edition>Ultimate</Edition>
<Edition>Premium</Edition>
<Edition>Pro</Edition>
</VisualStudio>

of course the actual flavors of VS you support depends on your extension.

 

2. Split the extension:

After changing the manifest you can compile your extension and see if it works on VS2012. In some cases it should work, but we had problems with the following assembly:

  • Microsoft.VisualStudio.ExtensibilityHosting

As we are using MEF inside our extension, we depend on that assembly. The point is you can’t use version 10 inside VS2012, it simply won’t work. Because of this problem, we ended up splitting the projects in the following way.

 

image

We keep the extension project (the one that contains the manifest) targeting .NET framework 4.0 which contains only references to assemblies that are compatible with VS2012  and we create two other specific projects:

  • Extension.v10 –> .Net 4.0 (this project in our case contains references to Microsoft.VisualStudio.ExtensibilityHosting v 10.0.0)
  • Extension.v11 –> .Net 4.5 (this contains Microsoft.VisualStudio.ExtensibilityHosting v 11.0.0)

Some considerations:

  • The extension project should contain references to Extension.v10 and Extension.v11 (the key here is to set the property “Reference output assembly” to false so the compile in .Net 4.0 despite Extension.v11 targets 4.5).
  • Don’t forget to add references to both assemblies in vsixmanifest
<Assembly AssemblyName="Extension.v10">|Extension.v10|</Assembly>
<Assembly AssemblyName="Extension.v11">|Extension.v11|</Assembly>

3. Dynamic load

When your extension is executing, depending on the Visual Studio version it’s running on, it should load the specific assembly for that version . To do that, ask the DTE about the version. Within your Package class, you can use a code similar to this to complete the job:

private const int MaxVsVersion = 11;

protected bool IsVisualStudio2010
        {
            get { return GetMajorVsVersion() == 10; }
        }

private int GetMajorVsVersion()
        {
            DTE dte = (DTE)this.GetService(typeof(DTE));
            string vsVersion = dte.Version;
            Version version;
            if (Version.TryParse(vsVersion, out version))
            {
                return version.Major;
            }
            return MaxVsVersion;
        }

Finally, load the assembly accordingly

 FileInfo assemblyFilename;
            if (IsVisualStudio2010)
                assemblyFilename = new FileInfo(Path.Combine(packageLocation,"Extension.v10.dll"));
            else
                assemblyFilename = new FileInfo(Path.Combine(packageLocation,"Extension.v11.dll"));

            Assembly assembly = Assembly.LoadFrom(assemblyFilename.FullName);

 

Then, you can use reflection or MEF to resolve what you need (the following code is an example using MEF)

var catalog = new AssemblyCatalog(assembly);
            var bootstrapContainer = new CompositionContainer(catalog);

            var export = bootstrapContainer.GetExportedValue<IBootstrapper>();
            container = export.GetContainer();

Hope It helps!

Hernán

Codealike: the first Microsoft´s partner for Visual Studio in Argentina.

Versión en Español.

The Argentine company has taken its relationship with Microsoft to an international level, by joining the Visual Studio Industry Partner Program so as to obtain exclusive access to technology.

Buenos Aires, Friday, March 2nd, 2012. – Codealike, a company whose aim is to bring productivity solutions to the software industry, announced just today that it is now one of Microsoft Visual Studio Industry Partners (VSIP), thus being the first Argentine Company that joins the program. The Visual Studio Industry Partner program was created at Microsoft`s main office in Redmond, United States of America, with the objective of allowing companies to have exclusive access to key technology. At the same time, it encourages companies to get quality standards that agree with the specifications established by Visual Studio, which is now the software development application mostly used by Fortune 1000 enterprises.

Being current software development teams highly collaborative, interruptions are a real problem to programmers, who sometimes waste the time equivalent to a whole month of their work in solving them. Codealike allows developers both to optimize collaboration and to recover from interruptions, thus improving their productivity. The idea is to give developers and managers some tools to administrate their time more efficiently and obtain metrics which have been, up to now, impossible to reach.

Consequently, Codelike becomes into the first Argentine company to join the Alliance and guarantee their users to have high quality products.

Federico Lois, one of Codealike´s founders, said: “By being part of the Visual Studio Industry Partner Program, we are able to make development processes faster because we have easy access to technical specifications and validations directly from the Product Team in Redmond. At the same time, we can guarantee our clients that we offer high quality products and that they will be able to get all future updates carried out by Visual Studio from us”. Furthermore, Sebastian Fernandez Quezada, another Codealike´s founder highlighted the importance of the agreement by stating: “There are approximately 150 companies around the world forming part of this Program created by Microsoft, including IBM, Borland, Intel and HP. Codealike is not only the first Argentine company to join the program, but also one of the few Latin American ones in doing so.”. Regarding the agreement Tom Lindeman, Director of the Visual Studio Industry Partner Program asserted “We are pleased to have Corvalius join the VSIP Program as the first Argentinian company and bring more depth to the Visual Studio ecosystem with Codealike”.

This agreement is additional to the one performed last January by Codealike and Microsoft in respect to Windows Azure, Microsoft´s cloud computing platform, by means of which the local company was able to start getting strategic technical access and support in Latin America and Redmond through the CSV program.

Codealike is accelerated by Wayra, which is the initiative launched by Grupo Telefónica in 2011.

 

For more information visit: http://www.codealike.com

Press Contact: press@corvalius.com

Codealike is a company from Corvalius.

 

Say hello to Codealike.

We would like to let you know that we’ll launch Codealike really soon (formerly known as Beweevee for Visual Studio). This new version will include new features that we came after considering users’ feedback and use while we were in Beta stage.

Codealike will be FREE for all Microsoft MVP, forever. So, let them all know the good news.

And if you’re not a Microsoft MVP, you can get early access to all of our new features if you register now.

Well, that’s pretty much it.

Feel free to register in: http://www.codealike.com and be ready to build a community around you.