3 Tips on Upgrading Your Visual Studio Extension 2022

Struggling to upgrade your Visual Studio extension?

New errors are appearing all the time? Getting frustrated?

Don’t worry about it! We took the hard way, and you can enjoy the fruits of our experience (and frustration). Here are the 3 main issues we encountered while working on integration and how to solve them.

Typemock Isolator extension was created a long time ago when Visual Studio 2010 was still the hotshot of the city. It shows how reliable and productive our company has been for over a decade, which gives us the possibility to produce top-notch products for every developer that practices unit testing. And who doesn’t unit test nowadays?

In order for the extension to be installed in Visual Studio 2022 you need to make 2 changes in the source source.extension.vsixmanifest  file:
1. Expand the Installation target property to support the new version, meaning change the version to support until “18.0” for example:

<InstallationTarget Id=”Microsoft.VisualStudio.Community” Version=”[17.0,18.0)”>

2. Because Visual studio 2022 is the first version that’s being installed as a 64-bit process, you need to add the 64-bit product architecture for it to be installed. For example:

<ProductArchitecture>amd64</ProductArchitecture>

To achieve those 2 modifications, you’ll need to update the Microsoft visual studio SDK package to the latest, which is version 17+. Doing so will create several issues.
Now let’s review the 3 main problems and how to solve them

Tip number 1:
If your extension depends on an old Microsoft API, for example the API from the following reference: “Microsoft.VisualStudio.Shell.10.0 “ then many build problems will occur for visual studio 2022. To solve this, change the projects that reference the old API to a shared project. Doing that will allow you to create 2 projects that use this shared project, one will reference the old API and the other will reference the new Microsoft API. A bit confused? Let’s look at the following solution:


As you can see we have a VSIX project (our extension for Visual Studio 2019 and earlier), another VSIX project for the Visual Studio 2022 extension, and another project which is referenced to the original VSIX project. When Microsoft released Visual Studio 2022 they also released a new version of Visual Studio SDK. This version removed a lot of the old API and also combined a lot of references into 1 package. This means that when you update your SDK package you might get errors such as: “The type <ABC> exists in both <ASSEMBLY1.dll> and <ASSEMBLY2.dll>”.

So how do you fix this?
Simple, create a new shared project which will contain all the files of the requested project, then create another project which will have the latest SDK package.

This will give you the ability to reference each project to the correct VSIX project.
For example, after the suggested solution above the solution should look like this:

Therefore, “Vsix_For_VS19_And_Earlier” will reference “oldApi” (like it was before).
“Vsix_For_VS22” will reference the new project which is “NewApi_for_VS22”.
“OldApi” and “NewApi_for_VS22” will use the “oldApi_Shared_Items”.
And finally, “Vsix_For_VS19_ And_Earlier” and “Vsix_For_VS22” will reference “Vsix_Shared_Items”.

Now you might ask, if my old project referenced the old API that means I’m using the old API in my code and the new API project will not compile. Well, you are correct and that leads us to tip number 2.

Tip number 2:
Conditional symbols, those 2 words save lives. Thanks to Microsoft, for every old API that got removed, there is a new API added. Here is a small example of using a conditional symbol in order to make your project compile:

You can see in the image, the API “QueryServiceAsync” signature has changed, and using conditional symbols we can support both old and new versions of the API. Without copying and duplicating our code – which will make maintenance complicated as each fix/new feature will need to be done in both files.

Tip number 3:
This tip is a bit more specific, our extension has a lot of XAML files which creates the UI windows. In some of those XAML files, we use the PlaformUI namespace for our windows. This namespace is a part of the “Microsoft.VisualStudio.Shell.10.0” dll. Here is the code line of that reference being used in XAML:

xmlns:ui=”clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.10.0

As explained in tip number 1, that caused us multiple errors like: “Type exists in both assemblies”. In the new Visual Studio SDK, this namespace is included in both “Microsoft.VisualStudio.Shell.10.0” and “Microsoft.VisualStudio.Shell.15.0”. Also, conditional symbols can’t be used inside a XAML file so the only solution was to duplicate the XAML file, put this file in the new project for Visual Studio 2022 (explained in tip 1), and change the assembly reference to “Microsoft.VisualStudio.Shell.15.0”, like

xmlns:ui=”clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0

This enables us to compile all the XAML files correctly without missing references or UI uses.

Of course, we can assure you that here at Typemock we have 10,000s of tests running automatically all the time, whose main purpose is making sure our product is completely safe and trustworthy, Writing those unit tests is making things easier to see errors, fix them and release them faster.

Those 3 tips helped us upgrade our extension to support Visual Studio 2022. I hope it will help you too. If you have any questions about this article, you can always ask us in our Community Forum.