/// <summary> /// Sets the value of the property. /// </summary> /// <param name="value">Property value to set.</param> /// <param name="configs">Optional list of configurations to set the property in; /// defaults to the project current configuration</param> /// <remarks> /// Before calling this method, the caller must ensure that the value is valid according to /// the <see cref="PropertyValidator"/> class, and that the project file is writable. /// In most cases the caller should also ensure that the new value is different from the /// existing value, to avoid dirtying the project file unnecessarily. /// </remarks> public void SetValue(string value, IList <ProjectConfig> configs) { WixHelperMethods.VerifyNonNullArgument(value, "value"); value = value.Trim(); PropertyPosition position = this.EndOfProjectFile ? PropertyPosition.UseExistingOrCreateAfterLastImport : PropertyPosition.UseExistingOrCreateAfterLastPropertyGroup; Project buildProject = this.project.BuildProject; if (this.PerUser) { if (this.project.UserBuildProject == null) { this.project.CreateUserBuildProject(); } buildProject = this.project.UserBuildProject; } value = this.Escape(value); if (this.PerConfig) { if (configs == null || configs.Count == 0) { configs = new ProjectConfig[] { this.project.CurrentConfig }; } foreach (ProjectConfig config in configs) { buildProject.SetProperty(this.propertyName, value, config.Condition, position); } } else { buildProject.SetProperty(this.propertyName, value, null, position); } this.project.InvalidatePropertyCache(); this.project.SetProjectFileDirty(true); }
ProjectPropertyGroupElement FindPropertyGroup(ProjectRootElement targetProject, string groupCondition, PropertyPosition position) { ProjectPropertyGroupElement matchedPropertyGroup = null; foreach (var projectItem in targetProject.Children) { ProjectPropertyGroupElement propertyGroup = projectItem as ProjectPropertyGroupElement; if (propertyGroup != null) { if (propertyGroup.Condition == groupCondition) { matchedPropertyGroup = propertyGroup; if (position != PropertyPosition.UseExistingOrCreateAfterLastImport) { return matchedPropertyGroup; } } } if (position == PropertyPosition.UseExistingOrCreateAfterLastImport) { if (projectItem is ProjectImportElement) { matchedPropertyGroup = null; } } } return matchedPropertyGroup; }
void MSBuildSetProperty(ProjectRootElement targetProject, string propertyName, string newValue, string groupCondition, PropertyPosition position, bool treatPropertyValueAsLiteral) { if (treatPropertyValueAsLiteral) newValue = MSBuildInternals.Escape(newValue); if (groupCondition == null) { // MSBuild uses an empty string when there's no condition, so we need to do the same // for the comparison to succeed. groupCondition = string.Empty; } foreach (var propertyGroup in targetProject.PropertyGroups) { if (propertyGroup.Condition == groupCondition) { foreach (var property in propertyGroup.Properties.ToList()) { if (MSBuildInternals.PropertyNameComparer.Equals(property.Name, propertyName)) { property.Value = newValue; return; } } } } var matchedPropertyGroup = FindPropertyGroup(targetProject, groupCondition, position); if (matchedPropertyGroup != null) { matchedPropertyGroup.AddProperty(propertyName, newValue); return; } var newGroup = AddNewPropertyGroup(targetProject, position); newGroup.Condition = groupCondition; newGroup.AddProperty(propertyName, newValue); }
/// <summary> /// Sets the value of an MSBuild project property. /// </summary> /// <param name="propertyName">The name of the property to change.</param> /// <param name="propertyValue">The value to assign the property.</param> /// <param name="condition">The condition to use on the property. Corresponds to the Condition attribute of the Property element.</param> /// <param name="position">A <see cref="PropertyPosition"/> value indicating the location to insert the property.</param> /// <param name="treatPropertyValueAsLiteral">true to treat the <paramref name="propertyValue"/> parameter as a literal value; otherwise, false.</param> public void SetProjectProperty(string propertyName, string propertyValue, string condition, PropertyPosition position, bool treatPropertyValueAsLiteral) { WixHelperMethods.VerifyStringArgument(propertyName, "propertyName"); if (propertyValue == null) { propertyValue = String.Empty; } // see if the value is the same as what's already in the project so we // know whether to actually mark the project file dirty or not string oldValue = this.GetProjectProperty(propertyName, true); if (!String.Equals(oldValue, propertyValue, StringComparison.Ordinal)) { // check out the project file if (this.ProjectMgr != null && !this.ProjectMgr.QueryEditProjectFile(false)) { throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED); } this.BuildProject.SetProperty(propertyName, propertyValue, condition, position, treatPropertyValueAsLiteral); // refresh the cached values this.SetCurrentConfiguration(); this.SetProjectFileDirty(true); } }
public void SetImportedProperty(string propertyName, string propertyValue, string condition, Project importedProject, PropertyPosition position, bool treatPropertyValueAsLiteral) { }
public void SetImportedProperty(string propertyName, string propertyValue, string condition, Project importedProject, PropertyPosition position) { }
public void SetProperty(string propertyName, string propertyValue, string condition, PropertyPosition position) { }
/// <summary> /// Set a property at a particular position inside an imported project file. /// The property will be in a group that has the specified condition. /// If necessary, a new property or property group will be created. /// </summary> /// <param name="propertyName">Property name.</param> /// <param name="propertyValue">Property value.</param> /// <param name="condition">The condition for this property.</param> /// <param name="importedProject">Specifies the project the property is imported from.</param> /// <param name="position">Specifies the position within the project file for the property.</param> /// <owner>DavidLe</owner> public void SetImportedProperty ( string propertyName, string propertyValue, string condition, Project importedProject, PropertyPosition position ) { SetPropertyAtHelper(propertyName, propertyValue, condition, /* importedProperty */ true, importedProject, position); importedProject.SetPropertyAtHelper(propertyName, propertyValue, condition, /* importedProperty */ false, null, position); }
private void UnlikelySortProperties(FastList <BlittableJsonDocumentBuilder.PropertyTag> properties) { _hasDuplicates = false; var index = GetPropertiesHashedIndex(properties); if (_cachedSorts[index] == null) { _cachedSorts[index] = new CachedSort(); } var cachedSort = _cachedSorts[index]; var sorting = cachedSort.Sorting; sorting.Clear(); for (int i = 0; i < properties.Count; i++) { sorting.Add(new PropertyPosition(properties[i].Property, -1)); } cachedSort.FinalCount = properties.Count; properties.Sort(ref _sorter); // The item comparison method has a side effect, which can modify the _hasDuplicates field. // This can either be true or false at any given time. if (_hasDuplicates) { // leave just the latest for (int i = 0; i < properties.Count - 1; i++) { if (properties[i].Property.Equals(properties[i + 1].Property)) { cachedSort.FinalCount--; sorting[i + 1] = new PropertyPosition( properties[i + 1].Property, // set it to the previous value, so it'll just overwrite // this saves us a check and more complex code sortedPosition: i ); properties.RemoveAt(i + 1); i--; } } } for (int i = 0; i < sorting.Count; i++) { var propPos = sorting[i]; propPos.SortedPosition = -1; for (int j = 0; j < properties.Count; j++) { if (properties[j].Property == propPos.Property) { propPos.SortedPosition = j; break; } } } }
/// <summary> /// Set a property at a particular position inside the project file. /// The property will be in a group that has the specified condition. /// If necessary, a new property or property group will be created. /// </summary> /// <param name="propertyName">Property name.</param> /// <param name="propertyValue">Property value.</param> /// <param name="condition">The condition for this property.</param> /// <param name="importedProperty">Is the property an imported property.</param> /// <param name="importedProject">The project from which the property is imported, if it is an imported property.</param> /// <param name="position">Specifies the position within the project file for the property.</param> /// <owner>RGoel, JomoF, DavidLe</owner> internal void SetPropertyAtHelper ( string propertyName, string propertyValue, string condition, bool importedProperty, Project importedProject, PropertyPosition position ) { // Property name must be non-empty. error.VerifyThrowArgumentLength(propertyName, "propertyName"); // Property value must be non-null. error.VerifyThrowArgument(propertyValue != null, "CannotSetPropertyToNull"); // Condition can be null, but that's the same as empty condition. if (condition == null) { condition = String.Empty; } // Is this an "after import" position? bool afterImportPosition = (position == PropertyPosition.UseExistingOrCreateAfterLastImport); BuildPropertyGroup matchingPropertyGroup = null; BuildProperty matchingProperty = null; string importedFilename = null; if (importedProperty) { importedFilename = importedProject.FullFileName; } // Find a matching property and\or property group. FindMatchingPropertyPosition(propertyName, condition, afterImportPosition, importedProperty, importedFilename, ref matchingPropertyGroup, ref matchingProperty); // If we found the property already in the project file, just change its value. if (matchingProperty != null) { matchingProperty.SetValue(propertyValue); } else { // Otherwise, add a new property to the last matching property group we // found. If we didn't find any matching property groups, create a new // one. if (matchingPropertyGroup == null) { if (importedProperty) { matchingPropertyGroup = this.AddNewImportedPropertyGroup(importedFilename, condition); } else { matchingPropertyGroup = this.AddNewPropertyGroup(afterImportPosition); matchingPropertyGroup.Condition = condition; } } if (importedProperty) { matchingPropertyGroup.AddNewImportedProperty(propertyName, propertyValue, importedProject); } else { matchingPropertyGroup.AddNewProperty(propertyName, propertyValue); } } }
/// <summary> /// Set a property at a particular position inside an imported project file. /// The property will be in a group that has the specified condition. /// If necessary, a new property or property group will be created. /// </summary> /// <param name="propertyName">Property name.</param> /// <param name="propertyValue">Property value.</param> /// <param name="condition">The condition for this property.</param> /// <param name="importedProject">Specifies the project the property is imported from.</param> /// <param name="position">Specifies the position within the project file for the property.</param> /// <param name="treatPropertyValueAsLiteral"></param> /// <owner>RGoel</owner> public void SetImportedProperty ( string propertyName, string propertyValue, string condition, Project importedProject, PropertyPosition position, bool treatPropertyValueAsLiteral ) { this.SetImportedProperty(propertyName, treatPropertyValueAsLiteral ? EscapingUtilities.Escape(propertyValue) : propertyValue, condition, importedProject, position); }
ProjectPropertyGroupElement AddNewPropertyGroup(ProjectRootElement targetProject, PropertyPosition position) { if (position == PropertyPosition.UseExistingOrCreateAfterLastImport) { var propertyGroup = targetProject.CreatePropertyGroupElement(); targetProject.AppendChild(propertyGroup); return propertyGroup; } return targetProject.AddPropertyGroup(); }
public void SetProperty(string propertyName, string propertyValue, string condition, PropertyPosition position, bool treatPropertyValueAsLiteral) { }
/// <summary> /// Sets a property in the MSBuild project file. /// </summary> /// <param name="propertyName">The name of the property to set.</param> /// <param name="propertyValue">The value of the property to set.</param> /// <param name="condition">The condition to use on the property. Corresponds to the Condition attribute of the Property element.</param> /// <param name="position">A <see cref="PropertyPosition"/> value indicating the location to insert the property.</param> /// <param name="treatPropertyValueAsLiteral">true to treat the <paramref name="propertyValue"/> parameter as a literal value; otherwise, false.</param> public void SetProperty(string propertyName, string propertyValue, string condition, PropertyPosition position, bool treatPropertyValueAsLiteral) { if (propertyValue == null) { propertyValue = String.Empty; } if (this.ProjectMgr != null) { this.ProjectMgr.SetProjectProperty(propertyName, propertyValue, condition, position, treatPropertyValueAsLiteral); } }