An ADR Visual Studio Tool – Part 6 – Visually Opening Files and Changing the Command Title

February 25, 2020

Following on from this post, which is the latest in a series on creating a Visual Studio Extension, I’m covering a couple of loose ends.

Visually Opening Files

In order to cause Visual Studio to open a file, you’ll need to call .Open on the ProjectItem; this returns a Window; if you then want this window to become visible, simply tell it so. All of this must be done on the UI thread:



            await Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
            var window = originalProjectItem.Open();
            window.Visible = true;

Change the Command Title

When you create an extension, by default it gets the same name as the project with the word ‘Window’ appended to it; in my case, that was AdrWindow. In order to change that, have a look for the file:



[ProjectName]Package.vsct

In my case, that was:



AdrPackage.vsct

For the default set-up, the button text will he here:

[code lang=“xml”] Adr Manager




# References

[https://stackoverflow.com/questions/26574839/developing-a-visual-studio-extension-how-to-open-a-source-file-and-jump-to-a-sp](https://stackoverflow.com/questions/26574839/developing-a-visual-studio-extension-how-to-open-a-source-file-and-jump-to-a-sp)


Profile picture

A blog about one man's journey through code… and some pictures of the Peak District
Twitter

© Paul Michaels 2022