示例#1
0
        /// <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>
        /// <returns>true if successfull.</returns>
        public static bool TryGetActiveConfigurationAndPlatform(System.IServiceProvider serviceProvider, Guid projectId, out ConfigCanonicalName configCanonicalName)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            IVsSolutionBuildManager5 solutionBuildManager = serviceProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager5;

            if (solutionBuildManager == null)
            {
                configCanonicalName = new ConfigCanonicalName();
                return(false);
            }

            string canonicalName;

            ErrorHandler.ThrowOnFailure(solutionBuildManager.FindActiveProjectCfgName(projectId, out canonicalName));

            configCanonicalName = new ConfigCanonicalName(canonicalName);

            return(true);
        }
        /// <summary>
        /// Deletes a specified platform name.
        /// </summary>
        /// <param name="platName">The platform name to delete.</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)
        {
            // We need to QE/QS the project file
            if (!this.ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            if (platName == null)
            {
                Debug.Fail(String.Format(CultureInfo.CurrentCulture, "Name of the platform should not be null if you want to delete it from project: {0}", MSBuildProject.GetFullPath((this.project.BuildProject))));
                return(VSConstants.S_OK);
            }

            this.project.BuildProject.ReevaluateIfNecessary();
            var configGroups   = new List <Microsoft.Build.Construction.ProjectPropertyGroupElement>(this.project.BuildProject.Xml.PropertyGroups);
            var groupsToDelete = new List <Microsoft.Build.Construction.ProjectPropertyGroupElement>();

            foreach (var config in configGroups)
            {
                var configCanonicalName = ConfigCanonicalName.OfCondition(config.Condition);
                if (configCanonicalName.MatchesPlatform(platName))
                {
                    groupsToDelete.Add(config);
                    configurationsList.Remove(configCanonicalName);
                }
            }

            foreach (var group in groupsToDelete)
            {
                group.Parent.RemoveChild(group);
            }

            NotifyOnPlatformNameDeleted(platName);

            return(VSConstants.S_OK);
        }
示例#3
0
        /// <summary>
        /// Retrives the configuration and the platform using the IVsSolutionBuildManager2 interface.
        /// </summary>
        /// <param name="serviceProvider">A service provider.</param>
        /// <param name="hierarchy">The hierarchy whose configuration is requested.  This method calls into
        /// native code and may be called on a background thread, so make sure the IVsHierarchy passed is
        /// safe to use for that sort of interop.</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>
        /// <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 ConfigCanonicalName configCanonicalName)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            if (hierarchy == null)
            {
                throw new ArgumentNullException("hierarchy");
            }

            IVsSolutionBuildManager2 solutionBuildManager = serviceProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;

            if (solutionBuildManager == null)
            {
                configCanonicalName = new ConfigCanonicalName();
                return(false);
            }

            IVsProjectCfg[] activeConfigs = new IVsProjectCfg[1];
            ErrorHandler.ThrowOnFailure(solutionBuildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy, activeConfigs));

            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));
            configCanonicalName = new ConfigCanonicalName(canonicalName);
            return(true);
        }
示例#4
0
 public ProjectOptions(ConfigCanonicalName configCanonicalName)
 {
     this.configCanonicalName = configCanonicalName;
 }
 internal virtual ProjectConfig CreateProjectConfiguration(ConfigCanonicalName canonicalName)
 {
     return(new ProjectConfig(this.project, canonicalName));
 }
        /// <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);
        }
示例#7
0
 protected override ProjectConfig CreateProjectConfiguration(ConfigCanonicalName canonicalName)
 {
     return(new XProjectConfig(this.ProjectMgr, canonicalName));
 }
示例#8
0
 /// <summary>
 /// Creates a new project config instance.
 /// </summary>
 /// <param name="project">Parent project node.</param>
 /// <param name="name">Canonical Name</param>
 public XProjectConfig(ProjectNode project, ConfigCanonicalName name)
     : base(project, name)
 {
 }
示例#9
0
        /// <summary>
        /// Copies an existing configuration name or creates a new one.
        /// </summary>
        /// <param name="name">The name of the new configuration.</param>
        /// <param name="cloneName">the name of the configuration to copy, or a null reference, indicating that AddCfgsOfCfgName should create a new configuration.</param>
        /// <param name="fPrivate">Flag indicating whether or not the new configuration is private. If fPrivate is set to true, the configuration is private. If set to false, the configuration is public. This flag can be ignored.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code. </returns>
        public virtual int AddCfgsOfCfgName(string name, string cloneName, int fPrivate)
        {
            // We need to QE/QS the project file
            if (!this.ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

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


            if (cloneName != 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 (String.Compare(configCanonicalName.ConfigName, cloneName, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        continue;
                    }

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


            var platforms = GetPlatformsFromProject();

            if (platforms.Length == 0)
            {
                platforms = new[] { String.Empty }
            }
            ;

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

                ProjectPropertyGroupElement newConfig = null;
                if (configToClone.ContainsKey(platform))
                {
                    // Clone the configuration settings
                    newConfig = this.project.ClonePropertyGroup(configToClone[platform]);
                    //Will be added later with the new values to the path
                    foreach (ProjectPropertyElement property in newConfig.Properties)
                    {
                        if (property.Name.Equals("OutputPath", StringComparison.OrdinalIgnoreCase))
                        {
                            property.Parent.RemoveChild(property);
                        }
                    }
                }
                else
                {
                    // no source to clone from, lets just create a new empty config
                    PopulateEmptyConfig(ref newConfig);
                    if (!String.IsNullOrEmpty(newCanonicalName.MSBuildPlatform))
                    {
                        newConfig.AddProperty(ProjectFileConstants.PlatformTarget, newCanonicalName.PlatformTarget);
                    }
                }


                //add the output path
                this.AddOutputPath(newConfig, name);

                // Set the condition that will define the new configuration
                string newCondition = newCanonicalName.ToMSBuildCondition();
                newConfig.Condition = newCondition;
            }
            NotifyOnCfgNameAdded(name);
            return(VSConstants.S_OK);
        }
 internal XSharpProjectConfig(ProjectNode project, ConfigCanonicalName configuration) : base(project, configuration)
 {
     _project = project;
 }
 protected override ProjectConfig CreateProjectConfiguration(ConfigCanonicalName canonicalName)
 {
     return(new XSharpProjectConfig(base.ProjectMgr, canonicalName));
 }
示例#12
0
 /// <summary>
 /// Creates a new project config instance.
 /// </summary>
 /// <param name="project">Parent project node.</param>
 /// <param name="name">Canonical Name</param>
 public XProjectConfig(ProjectNode project, ConfigCanonicalName name)
     : base(project, name)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
 }