Skip to content

Instantly share code, notes, and snippets.

@dogfuntom
Last active January 30, 2025 11:02
Show Gist options
  • Save dogfuntom/7b4b8aed2be09bfe164122d771d4580c to your computer and use it in GitHub Desktop.
Save dogfuntom/7b4b8aed2be09bfe164122d771d4580c to your computer and use it in GitHub Desktop.
VSIX options (Visual Studio settings) cookbook

Constansts, strings, variables

PageCategory

It is the category of option page itself. It must be the same string as in ProvideOptionPage attribute on your package class:

[ProvideOptionPage(typeof(FooPage), "<THIS STRING HERE>", ...)]
class FooPackage : AsyncPackage
{
...
}

PageName

It is the name of option page itself, as declared in ProvideOptionPage attribute on your package class:

[ProvideOptionPage(typeof(FooPage), PageCategory, "<THIS STRING HERE>", ...)]
class FooPackage : AsyncPackage
{
...
}

PropertyName

The actual name of a property in your code, not anything in the attributes. For example:

    [Category("Foo")]
    [DisplayName("Bar")]
    [Description("Baz")]
    [DefaultValue(true)]
    public bool Qux { get; set; } = true;

In this case the PropertyName is "Qux".

// See _common.md to learn what strings PageCategory, PageName and PropertyName are supposed to contain.
const string PageCategory = "Foo";
const string PageName = "Bar";
const string PropertyName = "Baz";
var dte = (DTE2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(DTE));
var props = dte.Properties[PageCategory, PageName];
// Read:
// Note that this can throw an exception if such property wasn't saved yet.
// Suppose the type of the property is bool, then:
var value = (bool)props.Item(PropertyName).Value;
// Write:
// Note that this can throw an exception if such property wasn't saved yet. I'm not sure how to add it manually.
props.Item(PropertyName).Value = value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment