コード例 #1
0
 /// <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);
     }
 }
コード例 #3
0
ファイル: IProject.cs プロジェクト: bangush/SharpDevelopLite
        public static ProjectBuildOptions CreateProjectBuildOptions(this IBuildable buildable, BuildOptions options, bool isRootBuildable)
        {
            IBuildable2 buildable2 = buildable as IBuildable2;

            if (buildable2 != null)
            {
                return(buildable2.CreateProjectBuildOptions(options, isRootBuildable));
            }
            // start of default implementation
            var configMatchings = buildable.ParentSolution.GetActiveConfigurationsAndPlatformsForProjects(options.SolutionConfiguration, options.SolutionPlatform);
            ProjectBuildOptions projectOptions = new ProjectBuildOptions(isRootBuildable ? options.ProjectTarget : options.TargetForDependencies);
            // Find the project configuration, and build an XML string containing all configurations from the solution
            StringWriter solutionConfigurationXml = new StringWriter();

            using (XmlTextWriter solutionConfigurationWriter = new XmlTextWriter(solutionConfigurationXml)) {
                solutionConfigurationWriter.WriteStartElement("SolutionConfiguration", "");
                foreach (var matching in configMatchings)
                {
                    if (matching.Project == buildable)
                    {
                        projectOptions.Configuration = matching.Configuration;
                        projectOptions.Platform      = matching.Platform;
                    }

                    solutionConfigurationWriter.WriteStartElement("ProjectConfiguration");
                    solutionConfigurationWriter.WriteAttributeString("Project", matching.Project.IdGuid);
                    solutionConfigurationWriter.WriteValue(matching.Configuration + "|" + MSBuildInternals.FixPlatformNameForProject(matching.Platform));
                    solutionConfigurationWriter.WriteEndElement();
                }
                solutionConfigurationWriter.WriteEndElement();
            }

            // fall back to solution config if we don't find any entries for the project
            if (string.IsNullOrEmpty(projectOptions.Configuration))
            {
                projectOptions.Configuration = options.SolutionConfiguration;
            }
            if (string.IsNullOrEmpty(projectOptions.Platform))
            {
                projectOptions.Platform = options.SolutionPlatform;
            }

            // copy properties to project options
            options.GlobalAdditionalProperties.ForEach(projectOptions.Properties.Add);
            if (isRootBuildable)
            {
                foreach (var pair in options.ProjectAdditionalProperties)
                {
                    projectOptions.Properties[pair.Key] = pair.Value;
                }
            }
            // Set property for solution configuration. This allows MSBuild to know the correct configuration for project references,
            // which is necessary to resolve the referenced project's OutputPath.
            projectOptions.Properties["CurrentSolutionConfigurationContents"] = solutionConfigurationXml.ToString();
            return(projectOptions);
        }
        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);
            }
        }
コード例 #5
0
 /// <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)));
         }
     }
 }
コード例 #6
0
        Entry GetOrCreateEntry(ConfigurationAndPlatform solutionConfiguration)
        {
            Entry entry;

            if (!dict.TryGetValue(solutionConfiguration, out entry))
            {
                var config = new ConfigurationAndPlatform(solutionConfiguration.Configuration, MSBuildInternals.FixPlatformNameForProject(solutionConfiguration.Platform));
                entry = new Entry(config);
                dict.Add(solutionConfiguration, entry);
            }
            return(entry);
        }