ImageOptimizer - Update a Visual Studio extension step by step
Article
This guide will show all the steps required for adding Visual Studio 2022 support while maintaining Visual Studio 2019 support using the Image Optimizer extension as a case study.
This is meant to be a thorough guide with git commit links to each step, but you are free to see the finalized PR here:
https://github.com/madskristensen/ImageOptimizer/pull/46.
First we bump the VSIX and unit test project to .NET 4.7.2 under the properties page of the projects:
Image Optimizer referenced some old custom 14.* and 15.* packages, instead we'll install the Microsoft.VisualStudio.Sdk NuGet package which consolidates all our required references.
Building the project succeeds and we get a few threading warnings. We fix these warnings by clicking ctrl and . and using intellisense to add the missing thread switching lines.
Step 2 - Refactor source code into a shared project
Supporting Visual Studio 2022 requires adding a new shared project that will contain the extension's source code which will be shared between the Visual Studio 2019 and Visual Studio 2022 VSIX projects.
Now move all the metadata, VSCT files, linked files, and external tools/libraries to a shared location and add them back as linked items to the VSIX project. Do not remove source.extension.vsixmanifest.
For this project we need to move the extension icon, VSCT file, and external tools to our new folder ImageOptimizer\Resources. Copy them to the shared folder and remove them from the VSIX project.
Added them back as linked items and if items are already linked items can stay as they are (license for example).
Validate that the Build Action and other properties are set correctly in the added linked files by selecting each one and checking the properties tool window. For our project we had to set the following:
Set icon.png Build Action to Content and marked Include in VSIX to true
Set ImageOptimizer.vsct Build Action to VSCTComplile and Include in VSIX to false
Set all the Build Action of the files under Resources\Tools to Content and marked Include in VSIX to true
Additionally, ImageOptimizer.cs is a dependency of ImageOptimizer.vsct, for this we have to manually add this dependency to the csproj file:
If the properties tool window prevents you from setting a specific Build Action, you can manually modify the csproj as done above and set the Build Action as needed.
Build your project to validate your changes and fix any error/issues. Check the Frequently Asked Questions section for common issues.
Add the linked files from your Visual Studio 2019 VSIX project and validate that their "Build Action" and "Include in VSIX" properties match. Also copy over your source.extension.vsixmanifest file, we'll be modifying it later to support Visual Studio 2022.