Пример #1
0
        /// <summary>
        /// Adds a new property group for a new configuration or platform.
        /// </summary>
        /// <param name="config">Configuration name of the full configuration being added.</param>
        /// <param name="platform">Platform name of the full configuration being added.</param>
        /// <param name="cloneCondition">Condition of property group to clone, if it exists.</param>
        private void AddNewConfigPropertyGroup(string config, string platform, string cloneCondition)
        {
            MSBuildConstruction.ProjectPropertyGroupElement newPropertyGroup = null;

            if (!String.IsNullOrEmpty(cloneCondition))
            {
                foreach (MSBuildConstruction.ProjectPropertyGroupElement propertyGroup in this.ProjectMgr.BuildProject.Xml.PropertyGroups)
                {
                    if (String.Equals(propertyGroup.Condition.Trim(), cloneCondition.Trim(), StringComparison.OrdinalIgnoreCase))
                    {
                        newPropertyGroup = this.ProjectMgr.ClonePropertyGroup(propertyGroup);
                        foreach (MSBuildConstruction.ProjectPropertyElement property in newPropertyGroup.Properties)
                        {
                            if (property.Name.Equals(WixProjectFileConstants.OutputPath) ||
                                property.Name.Equals(WixProjectFileConstants.IntermediateOutputPath))
                            {
                                property.Parent.RemoveChild(property);
                            }
                        }
                        break;
                    }
                }
            }

            if (newPropertyGroup == null)
            {
                newPropertyGroup = this.ProjectMgr.BuildProject.Xml.AddPropertyGroup();
                IList <KeyValuePair <KeyValuePair <string, string>, string> > propVals = this.NewConfigProperties;
                foreach (KeyValuePair <KeyValuePair <string, string>, string> data in propVals)
                {
                    KeyValuePair <string, string> propData = data.Key;
                    string value = data.Value;
                    MSBuildConstruction.ProjectPropertyElement newProperty = newPropertyGroup.AddProperty(propData.Key, value);
                    if (!String.IsNullOrEmpty(propData.Value))
                    {
                        newProperty.Condition = propData.Value;
                    }
                }
            }

            string outputBasePath = this.ProjectMgr.OutputBaseRelativePath;
            string outputPath     = Path.Combine(outputBasePath, WixConfigProvider.ConfigPath);

            newPropertyGroup.AddProperty(WixProjectFileConstants.OutputPath, outputPath);

            string intermediateBasePath = WixConfigProvider.IntermediateBaseRelativePath;
            string intermediatePath     = Path.Combine(intermediateBasePath, WixConfigProvider.ConfigPath);

            newPropertyGroup.AddProperty(WixProjectFileConstants.IntermediateOutputPath, intermediatePath);

            string newCondition = String.Format(CultureInfo.InvariantCulture, WixProjectConfig.ConfigAndPlatformConditionString, config, platform);

            newPropertyGroup.Condition = newCondition;
        }
        public ProjectPropertyElement AddProperty(string name, string value)
        {
            ProjectPropertyGroupElement parentGroup = null;

            foreach (var @group in PropertyGroups)
            {
                if (string.IsNullOrEmpty(@group.Condition))
                {
                    if (parentGroup == null)
                    {
                        parentGroup = @group;
                    }
                    var property = @group.Properties.
                                   Where(p => string.IsNullOrEmpty(p.Condition) &&
                                         p.Name.Equals(name, StringComparison.OrdinalIgnoreCase)).
                                   FirstOrDefault();
                    if (property != null)
                    {
                        property.Value = value;
                        return(property);
                    }
                }
            }
            if (parentGroup == null)
            {
                parentGroup = AddPropertyGroup();
            }
            return(parentGroup.AddProperty(name, value));
        }
Пример #3
0
        protected static void AddOrSetProperty(ProjectPropertyGroupElement group, string name, string value) {
            bool anySet = false;
            foreach (var prop in group.Properties.Where(p => p.Name == name)) {
                prop.Value = value;
                anySet = true;
            }

            if (!anySet) {
                group.AddProperty(name, value);
            }
        }
Пример #4
0
        /// <summary>
        /// Emulates the behavior of SetProperty(name, value, condition) on the old MSBuild object model.
        /// This finds a property group with the specified condition (or creates one if necessary) then sets the property in there.
        /// </summary>
        private void SetPropertyUnderCondition(string propertyName, string propertyValue, string condition)
        {
            string conditionTrimmed = (condition == null) ? String.Empty : condition.Trim();

            if (conditionTrimmed.Length == 0)
            {
                this.project.BuildProject.SetProperty(propertyName, propertyValue);
                return;
            }

            // New OM doesn't have a convenient equivalent for setting a property with a particular property group condition.
            // So do it ourselves.
            MSBuildConstruction.ProjectPropertyGroupElement newGroup = null;

            foreach (MSBuildConstruction.ProjectPropertyGroupElement group in this.project.BuildProject.Xml.PropertyGroups)
            {
                if (String.Equals(group.Condition.Trim(), conditionTrimmed, StringComparison.OrdinalIgnoreCase))
                {
                    newGroup = group;
                    break;
                }
            }

            if (newGroup == null)
            {
                newGroup           = this.project.BuildProject.Xml.AddPropertyGroup(); // Adds after last existing PG, else at start of project
                newGroup.Condition = condition;
            }

            foreach (MSBuildConstruction.ProjectPropertyElement property in newGroup.PropertiesReversed) // If there's dupes, pick the last one so we win
            {
                if (String.Equals(property.Name, propertyName, StringComparison.OrdinalIgnoreCase) && property.Condition.Length == 0)
                {
                    property.Value = propertyValue;
                    return;
                }
            }

            newGroup.AddProperty(propertyName, propertyValue);
        }
 private void AddFormattedPropGroup(string flagTag, List<ToolFlag> flags, Project proj, ProjectPropertyGroupElement group)
 {
     if (group == null)
     {
         AddFormattedPropGroup(flagTag, flags, proj);
     }
     else
     {
         foreach (ToolFlag flag in flags)
         {
             group.AddProperty(flagTag, ToEnvVar(flagTag) + flag.Flag);
         }
     }
 }
Пример #6
0
 void SetKnownProperties (ProjectPropertyGroupElement properties)
 {
         properties.AddProperty ("AssemblyName", Path.GetFileNameWithoutExtension ("ZigZag.exe"));
         properties.AddProperty ("ProjectGuid", projectGuid.ToString ("B"));
         properties.AddProperty ("CheckForOverflowUnderflow", false.ToString ());
         properties.AddProperty ("CodePage", String.Empty);
         properties.AddProperty ("DebugSymbols", true.ToString ());
         properties.AddProperty ("DebugType", "Full");
         properties.AddProperty ("Optimize", false.ToString ());
         properties.AddProperty ("Platform", "AnyCPU");
         properties.AddProperty ("ProjectTypeGuids", projectTypeGuid.ToString ("B"));
         properties.AddProperty ("AllowUnsafeBlocks", false.ToString ());
         properties.AddProperty ("WarningLevel", "4");
         properties.AddProperty ("OutputPath", ProjectCollection.Escape ("bin\\Debug"));
         properties.AddProperty ("OutputType", "winexe");
         properties.AddProperty ("DefineConstants", "DEBUG,TRACE");
         properties.AddProperty ("TreatWarningsAsErrors", true.ToString ());
 }
Пример #7
0
		private void AddOutputPath(ProjectPropertyGroupElement newConfig, string configName)
		{
			//add the output path
			string outputBasePath = this.ProjectMgr.OutputBaseRelativePath;
			if (outputBasePath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
				outputBasePath = Path.GetDirectoryName(outputBasePath);
			newConfig.AddProperty("OutputPath", Path.Combine(outputBasePath, configName) + Path.DirectorySeparatorChar.ToString());

		}
Пример #8
0
		private void PopulateEmptyConfig(ref ProjectPropertyGroupElement newConfig)
		{
			newConfig = this.project.BuildProject.Xml.AddPropertyGroup();
			// Get the list of property name, condition value from the config provider
			IList<KeyValuePair<KeyValuePair<string, string>, string>> propVals = this.NewConfigProperties;
			foreach (KeyValuePair<KeyValuePair<string, string>, string> data in propVals)
			{
				KeyValuePair<string, string> propData = data.Key;
				string value = data.Value;
				ProjectPropertyElement newProperty = newConfig.AddProperty(propData.Key, value);
				if (!String.IsNullOrEmpty(propData.Value))
					newProperty.Condition = propData.Value;
			}

		}
Пример #9
0
        private void PopulateEmptyConfig(ref ProjectPropertyGroupElement newConfig)
        {
            newConfig = this.project.BuildProject.Xml.AddPropertyGroup();
            foreach (KeyValuePair<KeyValuePair<string, string>, string> pair in this.NewConfigProperties)
            {
                var key = pair.Key;
                var unevaluatedValue = pair.Value;
                var element = newConfig.AddProperty(key.Key, unevaluatedValue);

                if (!string.IsNullOrEmpty(key.Value))
                    element.Condition = key.Value;
            }
        }
Пример #10
0
 static void createNullProperty(ProjectPropertyGroupElement ppge, string key, string val)
 {
     var avar = ppge.AddProperty(key, val);
     avar.Condition = "'" + propRef(key) + "'==''";
 }
Пример #11
0
        internal ProjectPropertyElement LookupProperty(ProjectPropertyGroupElement parent, string name, string condition = null) {
            ProjectPropertyElement property = null;

            var label = Pivots.GetExpressionLabel(condition);
            name = name.Replace(".", "_");

            if(string.IsNullOrEmpty(condition)) {
                property = parent.Properties.FirstOrDefault(each => name == each.Name && string.IsNullOrEmpty(each.Condition));
                if(property != null) {
                    return property;
                }
                return parent.AddProperty(name, "");
            }

            var conditionExpression = Pivots.GetMSBuildCondition(Name, condition);
            property = parent.Properties.FirstOrDefault(each => name == each.Name && each.Condition == conditionExpression);
            if(property != null) {
                return property;
            }

            property = parent.AddProperty(name, "");

            property.Label = label;
            property.Condition = conditionExpression;
            return property;
        }
Пример #12
0
 internal ProjectPropertyGroupElement AddPropertyInitializer(string propertyName, string conditionExpression, string value, ProjectPropertyGroupElement ppge = null) {
     ppge = ppge ?? Xml.AddPropertyGroup();
     ppge.Label = "Additional property initializers";
     ppge.AddProperty(propertyName, value).Condition = conditionExpression;
     return ppge;
 }
Пример #13
0
        /// <summary>
        /// Populate the property group with the individual options
        /// </summary>
        private void PopulatePropertyGroup(ProjectPropertyGroupElement configPropertyGroup)
        {
            string propertyName;

            foreach (CompSwitchInfo compSwitchInfo in validCompilerSwitches)
            {
                propertyName = compSwitchInfo.SwitchProjectPropertyName;

                // No need to remove the already existing property node
                // since the switches we are dealing with couldnt have been
                // set anywhere else in the property pages except the additional
                // options

                switch (compSwitchInfo.SwitchValueType)
                {
                    case SwitchValueType.SVT_Boolean:
                        if (null != compSwitchInfo.SwitchValue)
                        {
                            configPropertyGroup.AddProperty(
                                propertyName, 
                                compSwitchInfo.SwitchValue.ToString().ToLower(CultureInfo.InvariantCulture)
                            );
                        }
                    break;

                    case SwitchValueType.SVT_String:
                        if (null != compSwitchInfo.SwitchValue)
                        {
                            configPropertyGroup.AddProperty(
                                propertyName,
                                compSwitchInfo.SwitchValue.ToString()
                            );
                        }
                    break;

                    case SwitchValueType.SVT_MultiString:
                        Debug.Assert(null != compSwitchInfo.SwitchValue, "Expected non null value for multistring switch");
                        if (0 != ((StringBuilder)(compSwitchInfo.SwitchValue)).Length)
                        {
                            configPropertyGroup.AddProperty(
                                propertyName,
                                compSwitchInfo.SwitchValue.ToString()
                            );
                        }
                    break;

                    default:
                        Debug.Assert(false, "Unknown switch value type");
                    break;
                }
            }
        }
Пример #14
0
        /// <summary>
        /// Takes an XML element from an Everett project file, and loops through
        /// all its attributes.  For each attribute, it adds a new XMake property
        /// to the destination project file in the property group passed in.
        /// </summary>
        /// <owner>RGoel</owner>
        private void AddXMakePropertiesFromXMLAttributes
            (
            ProjectPropertyGroupElement propertyGroup,
            XmlElement          xmlElement
            )
        {
            error.VerifyThrow(propertyGroup != null, "Expected valid ProjectPropertyElementGroup to add properties to.");

            foreach (XmlAttribute xmlAttribute in xmlElement.Attributes)
            {
                // Add this as a property to the MSBuild project file.  If the property is one of those
                // that contains an identifier or a path, we must escape it to treat it as a literal.
                string value = xmlAttribute.Value;
                if (this.propertiesToEscape.ContainsKey(xmlAttribute.Name))
                {
                    value = ProjectCollection.Escape(value);
                }

                propertyGroup.AddProperty(xmlAttribute.Name, value);
            }
        }