/// <summary>
 /// Renames an entry.
 /// </summary>
 public void RenameSolutionConfiguration(ConfigurationAndPlatform sourceSolutionConfiguration, ConfigurationAndPlatform targetSolutionConfiguration)
 {
     lock (dict) {
         Entry entry;
         if (dict.TryGetValue(sourceSolutionConfiguration, out entry))
         {
             dict.Remove(sourceSolutionConfiguration);
             dict.Add(targetSolutionConfiguration, entry);
         }
     }
     Changed(this, EventArgs.Empty);
 }
        /// <summary>
        /// Removes all data stored about the specified solution configuration.
        /// </summary>
        public void Remove(ConfigurationAndPlatform solutionConfiguration)
        {
            bool result;

            lock (dict) {
                result = dict.Remove(solutionConfiguration);
            }
            if (result)
            {
                Changed(this, EventArgs.Empty);
            }
        }
        void GridCellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (!inUpdate && e.RowIndex >= 0)
            {
                DataGridViewRow row     = grid.Rows[e.RowIndex];
                IProject        project = (IProject)row.Tag;

                var newConfig = new ConfigurationAndPlatform(
                    GetValue(row.Cells[configurationColumn.Index]),
                    GetValue(row.Cells[platformColumn.Index]));

                project.ConfigurationMapping.SetProjectConfiguration(solutionConfig, newConfig);
            }
        }
 /// <summary>
 /// Gets whether building the project is enabled in the given solution configuration.
 /// </summary>
 public bool IsBuildEnabled(ConfigurationAndPlatform solutionConfiguration)
 {
     lock (dict) {
         Entry entry;
         if (dict.TryGetValue(solutionConfiguration, out entry))
         {
             return(entry.Build);
         }
         else
         {
             return(true);
         }
     }
 }
 /// <summary>
 /// Gets the project configuration corresponding to the given solution configuration.
 /// </summary>
 public ConfigurationAndPlatform GetProjectConfiguration(ConfigurationAndPlatform solutionConfiguration)
 {
     lock (dict) {
         Entry entry;
         if (dict.TryGetValue(solutionConfiguration, out entry))
         {
             return(entry.Config);
         }
         else
         {
             return(new ConfigurationAndPlatform(solutionConfiguration.Configuration, MSBuildInternals.FixPlatformNameForProject(solutionConfiguration.Platform)));
         }
     }
 }
 /// <summary>
 /// Gets whether deploying the project is enabled in the given solution configuration.
 /// </summary>
 public bool IsDeployEnabled(ConfigurationAndPlatform solutionConfiguration)
 {
     lock (dict) {
         Entry entry;
         if (dict.TryGetValue(solutionConfiguration, out entry))
         {
             return(entry.Deploy);
         }
         else
         {
             return(false);
         }
     }
 }
 public Task <BuildResults> BuildAsync(ISolution solution, BuildOptions options)
 {
     if (solution != null)
     {
         var solutionConfiguration = new ConfigurationAndPlatform(options.SolutionConfiguration ?? solution.ActiveConfiguration.Configuration,
                                                                  options.SolutionPlatform ?? solution.ActiveConfiguration.Platform);
         return(BuildAsync(solution.Projects.Where(p => p.ConfigurationMapping.IsBuildEnabled(solutionConfiguration)), options));
     }
     else
     {
         return(Task.FromResult(new BuildResults {
             Result = BuildResultCode.Error
         }));
     }
 }
Beispiel #8
0
 internal void LoadPreferences()
 {
     try {
         preferences = SD.PropertyService.LoadExtraProperties(GetPreferencesKey());
     } catch (IOException) {
     } catch (XmlException) {
         // ignore errors about inaccessible or malformed files
     }
     // Load active configuration from preferences
     CreateDefaultConfigurationsIfMissing();
     this.ActiveConfiguration = ConfigurationAndPlatform.FromKey(preferences.Get("ActiveConfiguration", "Debug|Any CPU"));
     ValidateConfiguration();
     // We can't set the startup project property yet; LoadPreferences() is called before
     // the projects are loaded into the solution.
     // This is necessary so that the projects can be loaded in the correct configuration
     // - we avoid an expensive configuration switch during solution load.
 }
 /// <summary>
 /// Sets the project configuration corresponding to the given solution configuration.
 /// </summary>
 public void SetProjectConfiguration(ConfigurationAndPlatform solutionConfiguration, ConfigurationAndPlatform projectConfiguration)
 {
     if (string.IsNullOrEmpty(projectConfiguration.Configuration))
     {
         throw new ArgumentException("Invalid project configuration");
     }
     if (string.IsNullOrEmpty(projectConfiguration.Platform))
     {
         throw new ArgumentException("Invalid project platform");
     }
     lock (dict) {
         GetOrCreateEntry(solutionConfiguration).Config = new ConfigurationAndPlatform(
             projectConfiguration.Configuration,
             MSBuildInternals.FixPlatformNameForProject(projectConfiguration.Platform)
             );
     }
     Changed(this, EventArgs.Empty);
 }
 public string ValidateName(string name)
 {
     if (name == null)
     {
         return(null);
     }
     name = name.Trim();
     if (!ConfigurationAndPlatform.IsValidName(name))
     {
         return(null);
     }
     if (isPlatform)
     {
         return(MSBuildInternals.FixPlatformNameForProject(name));
     }
     else
     {
         return(name);
     }
 }
        void AdjustMapping(string oldName, string newName)
        {
            var mapping = project.ConfigurationMapping;

            foreach (string solutionConfiguration in project.ParentSolution.ConfigurationNames)
            {
                foreach (string solutionPlatform in project.ParentSolution.PlatformNames)
                {
                    var solutionConfig = new ConfigurationAndPlatform(solutionConfiguration, solutionPlatform);
                    var projectConfig  = mapping.GetProjectConfiguration(solutionConfig);
                    if (HasName(projectConfig, oldName))
                    {
                        mapping.SetProjectConfiguration(solutionConfig, SetName(projectConfig, newName));
                    }
                }
            }
            // Adjust active configuration:
            if (HasName(project.ActiveConfiguration, oldName))
            {
                project.ActiveConfiguration = SetName(project.ActiveConfiguration, newName);
            }
        }
        void UpdateGrid()
        {
            inUpdate = true;

            solutionConfig = new ConfigurationAndPlatform(configurationComboBox.Text, platformComboBox.Text);

            foreach (DataGridViewRow row in grid.Rows)
            {
                IProject p = (IProject)row.Tag;

                var projectConfig = p.ConfigurationMapping.GetProjectConfiguration(solutionConfig);

                DataGridViewComboBoxCell c1 = (DataGridViewComboBoxCell)row.Cells[1];
                SetItemsAndSelect(c1, p.ConfigurationNames, projectConfig.Configuration);
                c1.Items.Add(EditTag.Instance);

                DataGridViewComboBoxCell c2 = (DataGridViewComboBoxCell)row.Cells[2];
                SetItemsAndSelect(c2, p.PlatformNames, projectConfig.Platform);
                c2.Items.Add(EditTag.Instance);
            }
            inUpdate = false;
        }
        void IConfigurationOrPlatformNameCollection.Remove(string name)
        {
            SD.MainThread.VerifyAccess();
            lock (project.SyncRoot) {
                string otherName = null;
                foreach (string configName in this)
                {
                    if (!ConfigurationAndPlatform.ConfigurationNameComparer.Equals(configName, name))
                    {
                        otherName = configName;
                        break;
                    }
                }
                if (otherName == null)
                {
                    throw new InvalidOperationException("cannot remove the last configuration/platform");
                }
                foreach (ProjectPropertyGroupElement g in project.MSBuildProjectFile.PropertyGroups.Concat(project.MSBuildUserProjectFile.PropertyGroups).ToList())
                {
                    ProjectPropertyElement prop = FindConfigElement(g);
                    if (prop != null && ConfigurationAndPlatform.ConfigurationNameComparer.Equals(prop.Value, name))
                    {
                        prop.Value = otherName;
                    }

                    var gConfig = ConfigurationAndPlatform.FromCondition(g.Condition);
                    if (HasName(gConfig, name))
                    {
                        g.Parent.RemoveChild(g);
                    }
                }
                project.LoadConfigurationPlatformNamesFromMSBuild();

                AdjustMapping(name, otherName);
            }
        }
 internal IEnumerable <ConfigurationAndPlatform> LoadSolutionConfigurations(IEnumerable <KeyValuePair <string, string> > section)
 {
     // Entries in the section look like this: 'Debug|Any CPU = Debug|Any CPU'
     return(section.Select(e => ConfigurationAndPlatform.FromKey(e.Key))
            .Where(e => ConfigurationAndPlatform.IsValidName(e.Configuration) && ConfigurationAndPlatform.IsValidName(e.Platform)));
 }
 public MSBuildItemDefinitionGroup(MSBuildBasedProject project, ConfigurationAndPlatform configuration)
     : this(project, configuration.ToCondition())
 {
 }
 public Entry(ConfigurationAndPlatform config)
 {
     this.Config = config;
 }
        /// <summary>
        /// copy properties from g into a new property group for newConfiguration and newPlatform
        /// </summary>
        void CopyProperties(ProjectRootElement project, ProjectPropertyGroupElement g, ConfigurationAndPlatform newConfig)
        {
            ProjectPropertyGroupElement ng = project.AddPropertyGroup();

            ng.Condition = newConfig.ToCondition();
            foreach (var p in g.Properties)
            {
                ng.AddProperty(p.Name, p.Value).Condition = p.Condition;
            }
        }
 bool HasName(ConfigurationAndPlatform config, string name)
 {
     return(ConfigurationAndPlatform.ConfigurationNameComparer.Equals(GetName(config), name));
 }
 string GetName(ConfigurationAndPlatform config)
 {
     return(isPlatform ? config.Platform : config.Configuration);
 }
        void IConfigurationOrPlatformNameCollection.Add(string newName, string copyFrom)
        {
            SD.MainThread.VerifyAccess();
            newName = ValidateName(newName);
            if (newName == null)
            {
                throw new ArgumentException();
            }
            lock (project.SyncRoot) {
                var  projectFile           = project.MSBuildProjectFile;
                var  userProjectFile       = project.MSBuildUserProjectFile;
                bool copiedGroupInMainFile = false;
                if (copyFrom != null)
                {
                    copyFrom = MSBuildInternals.FixPlatformNameForProject(copyFrom);
                    foreach (ProjectPropertyGroupElement g in projectFile.PropertyGroups.ToList())
                    {
                        var gConfig = ConfigurationAndPlatform.FromCondition(g.Condition);
                        if (HasName(gConfig, copyFrom))
                        {
                            CopyProperties(projectFile, g, SetName(gConfig, newName));
                            copiedGroupInMainFile = true;
                        }
                    }
                    foreach (ProjectPropertyGroupElement g in userProjectFile.PropertyGroups.ToList())
                    {
                        var gConfig = ConfigurationAndPlatform.FromCondition(g.Condition);
                        if (HasName(gConfig, copyFrom))
                        {
                            CopyProperties(userProjectFile, g, SetName(gConfig, newName));
                        }
                    }
                }
                if (!copiedGroupInMainFile)
                {
                    projectFile.AddPropertyGroup().Condition = (isPlatform ? new ConfigurationAndPlatform(null, newName) : new ConfigurationAndPlatform(newName, null)).ToCondition();
                }
                project.LoadConfigurationPlatformNamesFromMSBuild();

                // Adjust mapping:
                // If the new config/platform already exists in the solution and is mapped to some old project config/platform,
                // re-map it to the new config/platform.
                var mapping = project.ConfigurationMapping;
                if (isPlatform)
                {
                    string newNameForSolution = MSBuildInternals.FixPlatformNameForSolution(newName);
                    if (project.ParentSolution.PlatformNames.Contains(newNameForSolution, ConfigurationAndPlatform.ConfigurationNameComparer))
                    {
                        foreach (string solutionConfiguration in project.ParentSolution.ConfigurationNames)
                        {
                            var solutionConfig = new ConfigurationAndPlatform(solutionConfiguration, newNameForSolution);
                            var projectConfig  = mapping.GetProjectConfiguration(solutionConfig);
                            mapping.SetProjectConfiguration(solutionConfig, SetName(projectConfig, newName));
                        }
                    }
                }
                else
                {
                    if (project.ParentSolution.ConfigurationNames.Contains(newName, ConfigurationAndPlatform.ConfigurationNameComparer))
                    {
                        foreach (string solutionPlatform in project.ParentSolution.PlatformNames)
                        {
                            var solutionConfig = new ConfigurationAndPlatform(newName, solutionPlatform);
                            var projectConfig  = mapping.GetProjectConfiguration(solutionConfig);
                            mapping.SetProjectConfiguration(solutionConfig, SetName(projectConfig, newName));
                        }
                    }
                }
                project.ActiveConfiguration = mapping.GetProjectConfiguration(project.ParentSolution.ActiveConfiguration);
            }
        }
 /// <summary>
 /// Copies an entry.
 /// </summary>
 public void CopySolutionConfiguration(ConfigurationAndPlatform sourceSolutionConfiguration, ConfigurationAndPlatform targetSolutionConfiguration)
 {
     lock (dict) {
         Entry entry;
         if (dict.TryGetValue(sourceSolutionConfiguration, out entry))
         {
             dict[targetSolutionConfiguration] = entry.Clone();
         }
     }
     Changed(this, EventArgs.Empty);
 }