/// <summary>
/// Retrives the configuration and the platform using the IVsSolutionBuildManager2 interface.
/// </summary>
/// <param name="serviceProvider">A service provider.</param>
/// <param name="hierarchy">The hierrachy whose configuration is requested.</param>
/// <param name="configuration">The name of the active configuration.</param>
/// <param name="platform">The name of the platform.</param>
/// <returns>true if successfull.</returns>
internal static bool TryGetActiveConfigurationAndPlatform(System.IServiceProvider serviceProvider, IVsHierarchy hierarchy, out string configuration, out string platform)
{
if (serviceProvider == null)
{
throw new ArgumentNullException("serviceProvider");
}
if (hierarchy == null)
{
throw new ArgumentNullException("hierarchy");
}
configuration = String.Empty;
platform = String.Empty;
IVsSolutionBuildManager2 solutionBuildManager = serviceProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
if (solutionBuildManager == null)
{
return(false);
}
IVsProjectCfg[] activeConfigs = new IVsProjectCfg[1];
var res = solutionBuildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy, activeConfigs);
if (ErrorHandler.Failed(res))
{
return(false);
}
IVsProjectCfg activeCfg = activeConfigs[0];
// Can it be that the activeCfg is null?
System.Diagnostics.Debug.Assert(activeCfg != null, "Cannot find the active configuration");
string canonicalName;
ErrorHandler.ThrowOnFailure(activeCfg.get_CanonicalName(out canonicalName));
return(ProjectConfig.TrySplitConfigurationCanonicalName(canonicalName, out configuration, out platform));
}