MakeConfigKey() public static method

public static MakeConfigKey ( string>.Tuple canonicalConfigName ) : string
canonicalConfigName string>.Tuple
return string
Example #1
0
        /// <summary>
        /// Returns the per-configuration objects for this object.
        /// </summary>
        /// <param name="celt">Number of configuration objects to be returned or zero, indicating a request for an unknown number of objects.</param>
        /// <param name="a">On input, pointer to an interface array or a null reference. On output, this parameter points to an array of IVsCfg interfaces belonging to the requested configuration objects.</param>
        /// <param name="actual">The number of configuration objects actually returned or a null reference, if this information is not necessary.</param>
        /// <param name="flags">Flags that specify settings for project configurations, or a null reference (Nothing in Visual Basic) if no additional flag settings are required. For valid prgrFlags values, see __VSCFGFLAGS.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public virtual int GetCfgs(uint celt, IVsCfg[] a, uint[] actual, uint[] flags)
        {
            //if (celt == 1)
            //	Debug.WriteLine("GetCfgs(celt=1, ...)");

            if (flags != null)
            {
                flags[0] = 0;
            }

            int i = 0;

            string[] configList   = GetPropertiesConditionedOn(ProjectFileConstants.Configuration);
            string[] platformList = GetPlatformsFromProject();

            if (configList.Length == 0)
            {
                configList = new string[] { "Debug" }
            }
            ;
            if (platformList.Length == 0)
            {
                platformList = new string[] { "AnyCPU" }
            }
            ;

            if (a != null)
            {
                foreach (string configName in configList)
                {
                    foreach (string platform in platformList)
                    {
                        a[i] = this.GetProjectConfiguration(ProjectConfig.MakeConfigKey(configName, platform));

                        i++;
                        if (i == celt)
                        {
                            break;
                        }
                    }

                    if (i == celt)
                    {
                        break;
                    }
                }
            }
            else
            {
                i = configList.Length * platformList.Length;
            }

            if (actual != null)
            {
                actual[0] = (uint)i;
            }

            return(VSConstants.S_OK);
        }
        /// <summary>
        /// Deletes a specified platform name.
        /// </summary>
        /// <param name="platName">The platform name to delet.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public virtual int DeleteCfgsOfPlatformName(string platName)
        {
            if (!this.ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            var platform = ProjectConfig.ToMSBuildPlatform(platName);

            if (platform != null)
            {
                ProjectMgr.BuildProject.ReevaluateIfNecessary();
                var inputElements    = new List <ProjectPropertyGroupElement>(this.project.BuildProject.Xml.PropertyGroups);
                var elementsToRemove = new List <ProjectPropertyGroupElement>();

                foreach (ProjectPropertyGroupElement element in inputElements)
                {
                    var cfgNameAndPlatform = ProjectConfig.ConfigAndPlatformOfCondition(element.Condition);

                    if (ProjectConfig.EqPlatform(cfgNameAndPlatform.Item2, platform))
                    {
                        elementsToRemove.Add(element);
                        this.configurationsList.Remove(ProjectConfig.MakeConfigKey(cfgNameAndPlatform.Item1, cfgNameAndPlatform.Item2));
                    }
                }

                foreach (ProjectPropertyGroupElement element2 in elementsToRemove)
                {
                    element2.Parent.RemoveChild(element2);
                }

                NotifyOnPlatformNameDeleted(platform);
            }

            return(VSConstants.S_OK);
        }
        /// <summary>
        /// Assigns a new name to a configuration.
        /// </summary>
        /// <param name="old">The old name of the target configuration.</param>
        /// <param name="newname">The new name of the target configuration.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public virtual int RenameCfgsOfCfgName(string old, string newname)
        {
            this.project.BuildProject.ReevaluateIfNecessary();
            foreach (ProjectPropertyGroupElement current in this.project.BuildProject.Xml.PropertyGroups)
            {
                if (string.IsNullOrEmpty(current.Condition))
                {
                    continue;
                }

                var cfgNameAndPlatform = ProjectConfig.ConfigAndPlatformOfCondition(current.Condition);

                if (ProjectConfig.Eq(ProjectConfig.GetConfigName(cfgNameAndPlatform), old))
                {
                    //ConfigCanonicalName key2 = new ConfigCanonicalName(newname, key.Platform);
                    current.Condition = ProjectConfig.MakeMSBuildCondition(newname, cfgNameAndPlatform.Item2);

                    var outputPath = current.Properties.Where(p => p.Name == "OutputPath").FirstOrDefault();

                    if (outputPath != null && outputPath.Value != null)
                    {
                        string path = this.ProjectMgr.OutputBaseRelativePath;
                        if (path.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
                        {
                            path = Path.GetDirectoryName(path);
                        }

                        if (string.Equals(Path.Combine(path, old), outputPath.Value, StringComparison.OrdinalIgnoreCase))
                        {
                            current.SetProperty("OutputPath", Path.Combine(path, newname));
                        }
                    }

                    var oldKey = ProjectConfig.MakeConfigKey(cfgNameAndPlatform);

                    if (this.configurationsList.ContainsKey(oldKey))
                    {
                        ProjectConfig projectConfig = this.configurationsList[oldKey];
                        this.configurationsList.Remove(oldKey);
                        this.configurationsList.Add(ProjectConfig.MakeConfigKey(newname, cfgNameAndPlatform.Item2), projectConfig);
                        projectConfig.ConfigurationName = newname;
                    }
                }
            }

            this.NotifyOnCfgNameRenamed(old, newname);
            //// First create the condition that represent the configuration we want to rename
            //string condition = String.Format(CultureInfo.InvariantCulture, configString, old).Trim();

            //foreach (ProjectPropertyGroupElement config in this.project.BuildProject.Xml.PropertyGroups)
            //{
            //  // Only care about conditional property groups
            //  if (config.Condition == null || config.Condition.Length == 0)
            //    continue;

            //  // Skip if it isn't the group we want
            //  if (String.Compare(config.Condition.Trim(), condition, StringComparison.OrdinalIgnoreCase) != 0)
            //    continue;

            //  // Change the name
            //  config.Condition = String.Format(CultureInfo.InvariantCulture, configString, newname);
            //  // Update the name in our config list
            //  if (configurationsList.ContainsKey(old))
            //  {
            //    ProjectConfig configuration = configurationsList[old];
            //    configurationsList.Remove(old);
            //    configurationsList.Add(newname, configuration);
            //    // notify the configuration of its new name
            //    configuration.ConfigurationName = newname;
            //  }

            //  NotifyOnCfgNameRenamed(old, newname);
            //}

            return(VSConstants.S_OK);
        }
        /// <summary>
        /// Returns the configuration associated with a specified configuration or platform name.
        /// </summary>
        /// <param name="name">The name of the configuration to be returned.</param>
        /// <param name="platName">The name of the platform for the configuration to be returned.</param>
        /// <param name="cfg">The implementation of the IVsCfg interface.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public virtual int GetCfgOfName(string name, string platName, out IVsCfg cfg)
        {
            cfg = this.GetProjectConfiguration(ProjectConfig.MakeConfigKey(name, platName));

            return(VSConstants.S_OK);
        }