I am trying to add a property to our custom build configuration for a C++ project. I want the property combo box to display a dynamic list of values that I can set in code. I think that this should be done using the DynamicEnumProperty type but I am unsure of its implementation. Has anyone worked with this property before that can point me in the right direction?
Thanks
I know it's a bit old question... but you might still enjoy the solution ;)
Beside referencing the assemblies and exporting desired type via MEF as Dmitry explained above, you also need to mark the VSPackage as MEF-enabled to make it scan though your contracts. Do it by editing source.extension.vsixmanifest:
for VS2010:
for VS2012 / VS2013:
This should let you hit a breakpoint set in an exported class.
Additionally, if you need to create an object at runtime 'manually', you can use VisualStudio's internal composition container. The simplest way to access it from anywhere is:
I will shortly add a sample here: https://github.com/phofman/vs-plugin, so just putting the link for future reference.
In your
VSPackage
(or any MEF-exposed DLL referenced by it) create a class implementingIDynamicEnumValuesProvider
and add[Export(typeof(IDynamicEnumValuesProvider)), DynamicEnumCategory("MyCategory")]
to that class's attributes. Then addEnumProvider="MyCategory"
to theDynamicEnumProperty
definition and your class will be used as the values provider.Make sure your package references
Microsoft.VisualStudio.ProjectSystem.Utilities.v12.0.dll
andMicrosoft.VisualStudio.ProjectSystem.V12Only.dll
(for VS2013) or similar assemblies for earlier versions.