public BuildPropertyGroup Clone(bool deepClone) { BuildPropertyGroup bpg = new BuildPropertyGroup(propertyGroup, parentProject, importedProject, read_only); if (FromXml) { foreach (BuildProperty bp in properties) { if (deepClone) { bpg.AddProperty(bp.Clone(true)); } else { bpg.AddNewProperty(bp.Name, bp.FinalValue); } } } else { foreach (BuildProperty bp in propertiesByName.Values) { if (deepClone) { bpg.AddProperty(bp.Clone(true)); } else { bpg.AddNewProperty(bp.Name, bp.FinalValue); } } } return(bpg); }
public bool BuildProjectFile (string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs, string toolsVersion) { if (String.IsNullOrEmpty (projectFileName)) { string oldProjectToolsVersion = project.ToolsVersion; project.ToolsVersion = toolsVersion; try { return engine.BuildProject (project, targetNames, targetOutputs, BuildSettings.DoNotResetPreviouslyBuiltTargets); } finally { project.ToolsVersion = oldProjectToolsVersion; } } else { BuildPropertyGroup bpg = new BuildPropertyGroup (); if (globalProperties != null) foreach (DictionaryEntry de in globalProperties) bpg.AddProperty (new BuildProperty ( (string) de.Key, (string) de.Value, PropertyType.Global)); return engine.BuildProjectFile (projectFileName, targetNames, bpg, targetOutputs, BuildSettings.DoNotResetPreviouslyBuiltTargets, toolsVersion); } }
public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs, string toolsVersion) { if (String.IsNullOrEmpty(projectFileName)) { project.ToolsVersion = toolsVersion; return(engine.BuildProject(project, targetNames, targetOutputs, BuildSettings.DoNotResetPreviouslyBuiltTargets)); } else { BuildPropertyGroup bpg = new BuildPropertyGroup(); if (globalProperties != null) { foreach (DictionaryEntry de in globalProperties) { bpg.AddProperty(new BuildProperty( (string)de.Key, (string)de.Value, PropertyType.Global)); } } return(engine.BuildProjectFile(projectFileName, targetNames, bpg, targetOutputs, BuildSettings.DoNotResetPreviouslyBuiltTargets, toolsVersion)); } }
public BuildPropertyGroup Clone (bool deepClone) { BuildPropertyGroup bpg = new BuildPropertyGroup (propertyGroup, parentProject, importedProject, read_only); if (FromXml) { foreach (BuildProperty bp in properties) { if (deepClone) bpg.AddProperty (bp.Clone (true)); else bpg.AddNewProperty (bp.Name, bp.FinalValue); } } else { foreach (BuildProperty bp in propertiesByName.Values) { if (deepClone) bpg.AddProperty (bp.Clone (true)); else bpg.AddNewProperty (bp.Name, bp.FinalValue); } } return bpg; }
/// <summary> /// This method creates a copy of the BuildPropertyGroup. A shallow clone will reference the same BuildProperty objects as the /// original. A deep clone will deep clone the BuildProperty objects themselves. If this is a persisted BuildPropertyGroup, only /// deep clones are allowed, because you can't have the same XML element belonging to two parents. /// </summary> /// <owner>RGoel</owner> /// <param name="deepClone"></param> /// <returns>The cloned BuildPropertyGroup.</returns> public BuildPropertyGroup Clone ( bool deepClone ) { BuildPropertyGroup clone; if (IsVirtual) { // This is a virtual BuildPropertyGroup. MustBeVirtual("NeedVirtualPropertyGroup"); if (deepClone) { // Loop through every BuildProperty in our collection, and add those same properties // to the cloned collection. // Create a new virtual BuildPropertyGroup. // Do not set the ParentProject on the new BuildPropertyGroup, because it isn't really // part of the project clone = new BuildPropertyGroup(null, propertyTableByName.Count); foreach (DictionaryEntry propertyEntry in this.propertyTableByName) { // If the caller requested a deep clone, then deep clone the BuildProperty object, // and add the new BuildProperty to the new BuildPropertyGroup. clone.propertyTableByName.Add(propertyEntry.Key, ((BuildProperty)propertyEntry.Value).Clone(true /* deep clone */)); } // also clone over any overridden non-output properties if (this.propertiesOverriddenByOutputProperties != null) { clone.propertiesOverriddenByOutputProperties = new CopyOnWriteHashtable(propertiesOverriddenByOutputProperties.Count, StringComparer.OrdinalIgnoreCase); foreach (DictionaryEntry propertyEntry in this.propertiesOverriddenByOutputProperties) { if (propertyEntry.Value != null) { clone.propertiesOverriddenByOutputProperties.Add(propertyEntry.Key, ((BuildProperty)propertyEntry.Value).Clone(true /* deep clone */)); } else { clone.propertiesOverriddenByOutputProperties.Add(propertyEntry.Key, null); } } } } else { // shallow cloning is easy, we only clone the Hashtables clone = new BuildPropertyGroup(); clone.propertyTableByName = (CopyOnWriteHashtable)this.propertyTableByName.Clone(); if (this.propertiesOverriddenByOutputProperties != null) { clone.propertiesOverriddenByOutputProperties = (CopyOnWriteHashtable)this.propertiesOverriddenByOutputProperties.Clone(); } } } else { // This is a persisted <PropertyGroup>. MustBePersisted("NeedPersistedPropertyGroup", XMakeElements.propertyGroup); // Only deep clones are permitted when dealing with a persisted <PropertyGroup>. // This is because a shallow clone would attempt to add the same property // elements to two different parent <PropertyGroup> elements, and this is // not allowed. error.VerifyThrowInvalidOperation(deepClone, "ShallowCloneNotAllowed"); // Create a new persisted <PropertyGroup>. It won't actually get added // to any XmlDocument, but it will be associated with the same XmlDocument // as the current BuildPropertyGroup. clone = new BuildPropertyGroup ( null, /* Do not set the ParentProject on the cloned BuildPropertyGroup, because it isn't really part of the project */ ownerDocument, this.importedFromAnotherProject ); // Loop through every BuildProperty in our collection, and add those same properties // to the cloned collection. foreach (BuildProperty property in this) { // If the caller requested a deep clone, then deep clone the BuildProperty object, // and add the new BuildProperty to the new BuildPropertyGroup. Otherwise, just add // a reference to the existing BuildProperty object to the new BuildPropertyGroup. clone.AddProperty(property.Clone(true)); } clone.Condition = this.Condition; } // Return the cloned collection to the caller. return clone; }