0

OK, so I've managed to create a custom project flavor with a custom property page. It all works and the values are being saved to the .csproj file like such:

    <ProjectExtensions>
<VisualStudio>
  <FlavorProperties GUID="{880389B4-B814-4796-844B-F0E1678C31D1}" Configuration="Debug|Any CPU">
    <ServiceLibraryProjectFlavorCfg>
      <BooleanProperty>True</BooleanProperty>
    </ServiceLibraryProjectFlavorCfg>
  </FlavorProperties>
  <FlavorProperties GUID="{880389B4-B814-4796-844B-F0E1678C31D1}" Configuration="Release|Any CPU">
    <ServiceLibraryProjectFlavorCfg />
  </FlavorProperties>
</VisualStudio>

What I cant seem to figure out is how to access this custom property from, say, a menu item callback in my package. I can get the project that the selected item in the solution explorer which was right clicked belongs to, but I'm stuck after that...

Any help will be appreciated Thanx Hein

Matze
  • 5,100
  • 6
  • 46
  • 69

2 Answers2

2

OK, I figured it out.

As part of creating a custom project flavor, you inherit from FlavoredProjectBase and implement the IVsProjectFlavorCfgProvider interface.

the IVsProjectFlavorCfgProvider has one implementable method

int CreateProjectFlavorCfg(IVsCfg pBaseProjectCfg, out IVsProjectFlavorCfg ppFlavorCfg)

So here I implemented a static mapping between my custom IVsProjectFlavorCfg and the specified IVsCfg

Already having a EnvDTE.Project reference, I could then use the following to get a IVsCfg reference:

IVsHierarchy hierarchy1 = null;
var sol = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution;
sol.GetProjectOfUniqueName(project.UniqueName, out hierarchy1);

IVsSolutionBuildManager bm = Package.GetGlobalService(typeof(IVsSolutionBuildManager)) as IVsSolutionBuildManager;

IVsProjectCfg[] cfgs = new IVsProjectCfg[1];
bm.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy1, cfgs);

IVsCfg cfg = cfgs[0] as IVsCfg;

I could then use the IVsCfg reference to look up my custom configuration provider.

0

If you can access the project node instance (and if your project system is based on MPF), you can just use the GetProjectProperty method of the ProjectNode class. It obtains a ProjectPropertyInstance and returns its evaluated value, or null if the property does not exist.

Matze
  • 5,100
  • 6
  • 46
  • 69
  • I'm using Visual Studio 2015 & the VS SDK. I cant seem to find a ProjectNode class. Is MPF another library that sits on top of the SDK? I'm still very new at VSIX - it feels like I'm stumbling around in the dark :) – Hein Albrecht Mar 07 '16 at 11:04
  • `MPF` is the abbreviation for `Managed Package Framework`; its implemented on top of the SDK, see: https://msdn.microsoft.com/en-us/library/bb166360.aspx?f=255&MSPPError=-2147217396 Does your extension provide a custom language service? If not, MPF might not be ideal to work with... – Matze Mar 07 '16 at 12:31
  • No, I just want to create "Wizards" to generate multiple project items across multiple projects. I don't think I'll need MPF – Hein Albrecht Mar 07 '16 at 16:41