/// <summary>
        /// Creates new Project Configuartion objects based on the configuration name.
        /// </summary>
        /// <param name="canonicalName">The name of the configuration</param>
        /// <returns>An instance of a ProjectConfig object.</returns>
        internal ProjectConfig GetProjectConfiguration(ConfigCanonicalName canonicalName)
        {
            // if we already created it, return the cached one
            if (configurationsList.ContainsKey(canonicalName))
            {
                return configurationsList[canonicalName];
            }

            ProjectConfig requestedConfiguration = CreateProjectConfiguration(canonicalName);
            configurationsList.Add(canonicalName, requestedConfiguration);

            return requestedConfiguration;
        }
Beispiel #2
0
 public bool Equals(ConfigCanonicalName other)
 {
     return CMP.Equals(myConfigName, other.myConfigName) && CMP.Equals(myPlatform, other.myPlatform);
 }
Beispiel #3
0
        internal ProjectConfig(ProjectNode project, ConfigCanonicalName configName)
        {
            this.project = project;
            this.configCanonicalName = configName;
            this.fCanLaunchCache = -1;
            this.lastCache = DateTime.MinValue;
            this.projectConfigurationProperties = new ProjectConfigProperties(this);

            ErrorHandler.ThrowOnFailure(ProjectMgr.InteropSafeIVsProjectFlavorCfgProvider.CreateProjectFlavorCfg(this, out flavoredCfg));

            // if the flavored object support XML fragment, initialize it
            IPersistXMLFragment persistXML = flavoredCfg as IPersistXMLFragment;
            if (null != persistXML)
            {
                this.project.LoadXmlFragment(persistXML, this.DisplayName);
            }
        }
        /// <summary>
        /// Provides access to the IVsProjectCfg interface implemented on a project's configuration object. 
        /// </summary>
        /// <param name="projectCfgCanonicalName">The canonical name of the configuration to access.</param>
        /// <param name="projectCfg">The IVsProjectCfg interface of the configuration identified by szProjectCfgCanonicalName.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code. </returns>
        public virtual int OpenProjectCfg(string projectCfgCanonicalName, out IVsProjectCfg projectCfg)
        {
            if (projectCfgCanonicalName == null)
            {
                throw new ArgumentNullException("projectCfgCanonicalName");
            }

            projectCfg = null;

            // Be robust in release
            if (projectCfgCanonicalName == null)
            {
                return VSConstants.E_INVALIDARG;
            }


            Debug.Assert(this.project != null && this.project.BuildProject != null);

            string[] configs = GetPropertiesConditionedOn(ProjectFileConstants.Configuration);
            string[] platforms = GetPropertiesConditionedOn(ProjectFileConstants.Platform);
            var configCanonicalName = new ConfigCanonicalName(projectCfgCanonicalName);

            foreach (string config in configs)
            {
                foreach (string platform in platforms)
                {
                    if (configCanonicalName == new ConfigCanonicalName(config, platform))
                    {
                        projectCfg = this.GetProjectConfiguration(configCanonicalName);
                        if (projectCfg != null)
                        {
                            return VSConstants.S_OK;
                        }
                        else
                        {
                            return VSConstants.E_FAIL;
                        }
                    }
                }
            }

            return VSConstants.E_INVALIDARG;
        }
 internal virtual ProjectConfig CreateProjectConfiguration(ConfigCanonicalName canonicalName)
 {
     return new ProjectConfig(this.project, canonicalName);
 }
        /// <summary>
        /// Gets all the platforms defined in the project
        /// </summary>
        /// <returns>An array of platform names.</returns>
        private string[] GetPlatformsFromProject()
        {
            string[] platforms = GetPropertiesConditionedOn(ProjectFileConstants.Platform);
            if (platforms.Length == 0)
            {
                platforms = new[] { ProjectConfig.AnyCPU };
            }

            for (int i = 0; i < platforms.Length; i++)
            {
                platforms[i] = new ConfigCanonicalName("", platforms[i]).Platform;
            }

            return platforms;
        }
        /// <summary>
        /// Proved access to an IDispatchable object being a list of configuration properties
        /// </summary>
        /// <param name="configurationName">Combined Name and Platform for the configuration requested</param>
        /// <param name="configurationProperties">The IDispatchcable object</param>
        /// <returns>S_OK if successful</returns>
        public virtual int GetAutomationObject(string configurationName, out object configurationProperties)
        {
            //Init out param
            configurationProperties = null;

            var canonicalCfgName = new ConfigCanonicalName(configurationName);

            // Get the configuration
            IVsCfg cfg;
            ErrorHandler.ThrowOnFailure(this.GetCfgOfName(canonicalCfgName.ConfigName, canonicalCfgName.Platform, out cfg));

            // Get the properties of the configuration
            configurationProperties = ((ProjectConfig)cfg).ConfigurationProperties;

            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 (var config in this.project.BuildProject.Xml.PropertyGroups)
            {
                // Only care about conditional property groups
                if (config.Condition == null || config.Condition.Length == 0)
                    continue;

                var configCanonicalName = ConfigCanonicalName.OfCondition(config.Condition);
                // Skip if it isn't the group we want
                if (!configCanonicalName.MatchesConfigName(old))
                    continue;

                var newCanonicalName = new ConfigCanonicalName(newname, configCanonicalName.Platform);
                // Change the name 
                config.Condition = newCanonicalName.ToMSBuildCondition();
                var propertyCollection = config.Properties;
                var outputPathProperty = propertyCollection.Where(p => p.Name == ProjectFileConstants.OutputPath).FirstOrDefault();
                if (outputPathProperty != null)
                {
                    string outputBasePath = this.ProjectMgr.OutputBaseRelativePath;
                    if (outputBasePath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
                        outputBasePath = Path.GetDirectoryName(outputBasePath);
                    var expectedOutputPathValue = Path.Combine(outputBasePath, old);
                    if (String.Equals(expectedOutputPathValue, outputPathProperty.Value, StringComparison.OrdinalIgnoreCase))
                    {
                        var newOutputPathValue = Path.Combine(outputBasePath, newname);
                        config.SetProperty(ProjectFileConstants.OutputPath, newOutputPathValue);
                    }
                }
                // Update the name in our config list   
                if (configurationsList.ContainsKey(configCanonicalName))
                {
                    ProjectConfig configuration = configurationsList[configCanonicalName];
                    configurationsList.Remove(configCanonicalName);
                    configurationsList.Add(newCanonicalName, configuration);
                    // notify the configuration of its new name
                    configuration.ConfigName = newname;
                }                

            }
            NotifyOnCfgNameRenamed(old, newname);

            return VSConstants.S_OK;
        }
        /// <summary>
        /// Copies an existing platform name or creates a new one. 
        /// </summary>
        /// <param name="platformName">The name of the new platform.</param>
        /// <param name="clonePlatformName">The name of the platform to copy, or a null reference, indicating that AddCfgsOfPlatformName should create a new platform.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public virtual int AddCfgsOfPlatformName(string platformName, string clonePlatformName)
        {
            // We need to QE/QS the project file
            if (!this.ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            // Get all configs
            this.project.BuildProject.ReevaluateIfNecessary();
            List<Microsoft.Build.Construction.ProjectPropertyGroupElement> configGroup = new List<Microsoft.Build.Construction.ProjectPropertyGroupElement>(this.project.BuildProject.Xml.PropertyGroups);
            // configName -> property group
            var configToClone = new Dictionary<string, Microsoft.Build.Construction.ProjectPropertyGroupElement>(StringComparer.Ordinal);


            if (clonePlatformName != null)
            {
                // Find the configuration to clone
                foreach (var currentConfig in configGroup)
                {
                    // Only care about conditional property groups
                    if (currentConfig.Condition == null || currentConfig.Condition.Length == 0)
                        continue;
                    var configCanonicalName = ConfigCanonicalName.OfCondition(currentConfig.Condition);

                    // Skip if it isn't the group we want
                    if (!configCanonicalName.MatchesPlatform(clonePlatformName))
                        continue;

                    if (!configToClone.ContainsKey(configCanonicalName.ConfigName))
                        configToClone.Add(configCanonicalName.ConfigName, currentConfig);
                }
            }


            var configNames = GetPropertiesConditionedOn(ProjectFileConstants.Configuration);
            if (configNames.Length == 0) return VSConstants.E_FAIL;

            foreach (var configName in configNames)
            {
                // If we have any property groups to clone, and we do not have sourec for this config, skip
                if (configToClone.Count > 0 && !configToClone.ContainsKey(configName)) continue;
                var newCanonicalName = new ConfigCanonicalName(configName, platformName);

                Microsoft.Build.Construction.ProjectPropertyGroupElement newConfig = null;
                if (configToClone.ContainsKey(configName))
                {
                    // Clone the configuration settings
                    newConfig = this.project.ClonePropertyGroup(configToClone[configName]);
                    foreach (Microsoft.Build.Construction.ProjectPropertyElement property in newConfig.Properties)
                    {
                        if (property.Name.Equals(ProjectFileConstants.PlatformTarget, StringComparison.OrdinalIgnoreCase))
                        {
                            property.Parent.RemoveChild(property);
                        }
                    }

                }
                else
                {
                    // no source to clone from, lets just create a new empty config
                    PopulateEmptyConfig(ref newConfig);
                    this.AddOutputPath(newConfig, configName);
                }

                newConfig.AddProperty(ProjectFileConstants.PlatformTarget, newCanonicalName.PlatformTarget);

                // Set the condition that will define the new configuration
                string newCondition = newCanonicalName.ToMSBuildCondition();
                newConfig.Condition = newCondition;
            }
            NotifyOnPlatformNameAdded(platformName);
            return VSConstants.S_OK;

        }
Beispiel #10
0
 public ProjectOptions(ConfigCanonicalName configCanonicalName)
 {
     this.configCanonicalName = configCanonicalName;
 }