private static void MergeIntoPropertyDictionary( PropertyDictionary <ProjectPropertyInstance> properties, string propertyNameAndValuesString, string syntaxName) { if (!string.IsNullOrEmpty(propertyNameAndValuesString)) { if (PropertyParser.GetTableWithEscaping( null, null, null, propertyNameAndValuesString.Split(PropertySeparator, StringSplitOptions.RemoveEmptyEntries), out Dictionary <string, string> propertiesTable)) { foreach (KeyValuePair <string, string> pair in propertiesTable) { properties[pair.Key] = ProjectPropertyInstance.Create(pair.Key, pair.Value); } } else { throw new InvalidProjectFileException(string.Format( CultureInfo.InvariantCulture, ResourceUtilities.GetResourceString("General.InvalidPropertyError"), syntaxName, propertyNameAndValuesString)); } } }
/// <summary> /// A new build request from the node for a project which was already previously built in that node but for a different global properties /// </summary> public void ReferenceAProjectAlreadyBuiltInTheNodeButWithDifferentGlobalProperties() { ProjectPropertyInstance prop1 = ProjectPropertyInstance.Create("prop1", "Value1"); ProjectPropertyInstance prop2 = ProjectPropertyInstance.Create("prop2", "Value2"); PropertyDictionary <ProjectPropertyInstance> group1 = new PropertyDictionary <ProjectPropertyInstance>(); group1.Set(prop1); PropertyDictionary <ProjectPropertyInstance> group2 = new PropertyDictionary <ProjectPropertyInstance>(); group2.Set(prop2); RequestDefinition p1 = CreateNewRequest("1.proj", "2.0", new string[1] { "t1" }, group1); RequestDefinition p2 = CreateNewRequest("2.proj"); RequestDefinition p3 = CreateNewRequest("1.proj", "2.0", new string[1] { "t1" }, group2); p2.AddChildDefinition(p3); p1.SubmitBuildRequest(); p1.ValidateBuildResult(); p2.SubmitBuildRequest(); p2.ValidateBuildResult(); }
public void OldSyntaxTests() { Parser p = new Parser(); ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create()); ItemDictionary <ProjectItemInstance> itemBag = new ItemDictionary <ProjectItemInstance>(); itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath)); itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath)); itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath)); PropertyDictionary <ProjectPropertyInstance> propertyBag = new PropertyDictionary <ProjectPropertyInstance>(); propertyBag.Set(ProjectPropertyInstance.Create("foo", "true")); propertyBag.Set(ProjectPropertyInstance.Create("bar", "yes")); propertyBag.Set(ProjectPropertyInstance.Create("one", "1")); propertyBag.Set(ProjectPropertyInstance.Create("onepointzero", "1.0")); propertyBag.Set(ProjectPropertyInstance.Create("two", "2")); propertyBag.Set(ProjectPropertyInstance.Create("simple", "simplestring")); propertyBag.Set(ProjectPropertyInstance.Create("complex", "This is a complex string")); propertyBag.Set(ProjectPropertyInstance.Create("c1", "Another (complex) one.")); propertyBag.Set(ProjectPropertyInstance.Create("c2", "Another (complex) one.")); Expander <ProjectPropertyInstance, ProjectItemInstance> expander = new Expander <ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag, FileSystems.Default); AssertParseEvaluate(p, "(($(foo) != 'two' and $(bar)) and 5 >= 1) or $(one) == 1", expander, true); }
/// <summary> /// Submit 3 build request where first one has multiple references and last has multiple references. Some of the references are built with different global properties /// </summary> public void BuildMultipleProjectsWithReferencesAndDifferentGlobalProperties() { ProjectPropertyInstance prop1 = ProjectPropertyInstance.Create("prop1", "Value1"); ProjectPropertyInstance prop2 = ProjectPropertyInstance.Create("prop2", "Value2"); PropertyDictionary <ProjectPropertyInstance> group1 = new PropertyDictionary <ProjectPropertyInstance>(); group1.Set(prop1); PropertyDictionary <ProjectPropertyInstance> group2 = new PropertyDictionary <ProjectPropertyInstance>(); group2.Set(prop2); RequestDefinition p1 = CreateNewRequest("1.proj"); RequestDefinition p2 = CreateNewRequest("2.proj"); RequestDefinition p3 = CreateNewRequest("3.proj"); RequestDefinition p4 = CreateNewRequest("4.proj"); RequestDefinition p5 = CreateNewRequest("2.proj", group1); RequestDefinition p6 = CreateNewRequest("6.proj"); RequestDefinition p7 = CreateNewRequest("2.proj", group2); p1.AddChildDefinition(p4); p1.AddChildDefinition(p5); p3.AddChildDefinition(p6); p3.AddChildDefinition(p7); p1.SubmitBuildRequest(); p1.ValidateBuildResult(); p2.SubmitBuildRequest(); p2.ValidateBuildResult(); p3.SubmitBuildRequest(); p3.ValidateBuildResult(); }
private static List <ConfigurationMetadata> AddGraphBuildPropertyToEntryPoints(IEnumerable <ProjectGraphEntryPoint> entryPoints) { { var entryPointConfigurationMetadata = new List <ConfigurationMetadata>(); foreach (var entryPoint in entryPoints) { var globalPropertyDictionary = CreatePropertyDictionary(entryPoint.GlobalProperties); AddGraphBuildGlobalVariable(globalPropertyDictionary); var configurationMetadata = new ConfigurationMetadata(FileUtilities.NormalizePath(entryPoint.ProjectFile), globalPropertyDictionary); entryPointConfigurationMetadata.Add(configurationMetadata); } return(entryPointConfigurationMetadata); } void AddGraphBuildGlobalVariable(PropertyDictionary <ProjectPropertyInstance> globalPropertyDictionary) { if (globalPropertyDictionary.GetProperty(PropertyNames.IsGraphBuild) == null) { globalPropertyDictionary[PropertyNames.IsGraphBuild] = ProjectPropertyInstance.Create(PropertyNames.IsGraphBuild, "true"); } } }
public void StringExpansionTests() { Parser p = new Parser(); ProjectInstance parentProject = new ProjectInstance(ProjectRootElement.Create()); ItemDictionary <ProjectItemInstance> itemBag = new ItemDictionary <ProjectItemInstance>(); itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "foo.cs", parentProject.FullPath)); itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "bar.cs", parentProject.FullPath)); itemBag.Add(new ProjectItemInstance(parentProject, "Compile", "baz.cs", parentProject.FullPath)); PropertyDictionary <ProjectPropertyInstance> propertyBag = new PropertyDictionary <ProjectPropertyInstance>(); propertyBag.Set(ProjectPropertyInstance.Create("foo", "true")); propertyBag.Set(ProjectPropertyInstance.Create("bar", "yes")); propertyBag.Set(ProjectPropertyInstance.Create("one", "1")); propertyBag.Set(ProjectPropertyInstance.Create("onepointzero", "1.0")); propertyBag.Set(ProjectPropertyInstance.Create("two", "2")); propertyBag.Set(ProjectPropertyInstance.Create("simple", "simplestring")); propertyBag.Set(ProjectPropertyInstance.Create("complex", "This is a complex string")); propertyBag.Set(ProjectPropertyInstance.Create("c1", "Another (complex) one.")); propertyBag.Set(ProjectPropertyInstance.Create("c2", "Another (complex) one.")); propertyBag.Set(ProjectPropertyInstance.Create("TestQuote", "Contains'Quote'")); propertyBag.Set(ProjectPropertyInstance.Create("AnotherTestQuote", "Here's Johnny!")); propertyBag.Set(ProjectPropertyInstance.Create("Atsign", "Test the @ replacement")); Expander <ProjectPropertyInstance, ProjectItemInstance> expander = new Expander <ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag, FileSystems.Default); AssertParseEvaluate(p, "'simplestring: true foo.cs;bar.cs;baz.cs' == '$(simple): $(foo) @(compile)'", expander, true); AssertParseEvaluate(p, "'$(c1) $(c2)' == 'Another (complex) one. Another (complex) one.'", expander, true); AssertParseEvaluate(p, "'CONTAINS%27QUOTE%27' == '$(TestQuote)'", expander, true); AssertParseEvaluate(p, "'Here%27s Johnny!' == '$(AnotherTestQuote)'", expander, true); AssertParseEvaluate(p, "'Test the %40 replacement' == $(Atsign)", expander, true); }
public void TestEquals() { BuildRequestConfiguration config1 = new BuildRequestConfiguration(new BuildRequestData("file", new Dictionary <string, string>(), "toolsVersion", new string[0], null), "2.0"); Assert.Equal(config1, config1); BuildRequestConfiguration config2 = new BuildRequestConfiguration(new BuildRequestData("file", new Dictionary <string, string>(), "toolsVersion", new string[0], null), "2.0"); Assert.Equal(config1, config2); BuildRequestConfiguration config3 = new BuildRequestConfiguration(new BuildRequestData("file2", new Dictionary <string, string>(), "toolsVersion", new string[0], null), "2.0"); Assert.NotEqual(config1, config3); BuildRequestConfiguration config4 = new BuildRequestConfiguration(new BuildRequestData("file", new Dictionary <string, string>(), "toolsVersion2", new string[0], null), "2.0"); Assert.NotEqual(config1, config4); PropertyDictionary <ProjectPropertyInstance> props = new PropertyDictionary <ProjectPropertyInstance>(); props.Set(ProjectPropertyInstance.Create("prop1", "value1")); BuildRequestData data = new BuildRequestData("file", props.ToDictionary(), "toolsVersion", new string[0], null); BuildRequestConfiguration config5 = new BuildRequestConfiguration(data, "2.0"); Assert.NotEqual(config1, config5); Assert.Equal(config1, config2); Assert.NotEqual(config1, config3); }
internal void CreateUniqueGlobalProperty() { // create a copy so the mutation does not leak into the ProjectInstance _globalProperties = new PropertyDictionary <ProjectPropertyInstance>(_globalProperties); var key = $"{MSBuildConstants.MSBuildDummyGlobalPropertyHeader}{Guid.NewGuid():N}"; _globalProperties[key] = ProjectPropertyInstance.Create(key, "Forces unique project identity in the MSBuild engine"); }
private static void MergeIntoPropertyDictionary( PropertyDictionary <ProjectPropertyInstance> destination, IReadOnlyDictionary <string, string> source) { foreach (var pair in source) { destination[pair.Key] = ProjectPropertyInstance.Create(pair.Key, pair.Value); } }
public void EqualsEndPastEnd1() { PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(); ProjectPropertyInstance p = ProjectPropertyInstance.Create("bbb", "value"); dictionary.Set(p); ProjectPropertyInstance value = MSBuildNameIgnoreCaseComparer.Mutable.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, "abbbaaa", 1, 3); Assert.True(Object.ReferenceEquals(p, value)); // "Should have returned the same object as was inserted" }
public ConfigurationMetadata(Project project) { ErrorUtilities.VerifyThrowArgumentNull(project, nameof(project)); _globalProperties = new PropertyDictionary <ProjectPropertyInstance>(project.GlobalProperties.Count); foreach (KeyValuePair <string, string> entry in project.GlobalProperties) { _globalProperties[entry.Key] = ProjectPropertyInstance.Create(entry.Key, entry.Value); } _toolsVersion = project.ToolsVersion; _projectFullPath = FileUtilities.NormalizePath(project.FullPath); }
public void EqualsStartZero() { PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(); ProjectPropertyInstance p1 = ProjectPropertyInstance.Create("aab", "value1"); ProjectPropertyInstance p2 = ProjectPropertyInstance.Create("aba", "value2"); dictionary.Set(p1); dictionary.Set(p2); ProjectPropertyInstance value = MSBuildNameIgnoreCaseComparer.Mutable.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, "aabaa", 0, 2); Assert.True(Object.ReferenceEquals(p1, value)); // "Should have returned the 'aab' value" }
public void EqualsSameStartEnd1() { PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(); ProjectPropertyInstance p1 = ProjectPropertyInstance.Create("A", "value1"); ProjectPropertyInstance p2 = ProjectPropertyInstance.Create("B", "value2"); dictionary.Set(p1); dictionary.Set(p2); ProjectPropertyInstance value = MSBuildNameIgnoreCaseComparer.Mutable.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, "babbbb", 1, 1); Assert.IsTrue(Object.ReferenceEquals(p1, value), "Should have returned the 'A' value"); }
/// <summary> /// Set up expression tests by creating files for existence checks. /// </summary> public ExpressionTest(ITestOutputHelper output) { this.output = output; ItemDictionary <ProjectItemInstance> itemBag = new ItemDictionary <ProjectItemInstance>(); // Dummy project instance to own the items. ProjectRootElement xml = ProjectRootElement.Create(); xml.FullPath = @"c:\abc\foo.proj"; ProjectInstance parentProject = new ProjectInstance(xml); itemBag.Add(new ProjectItemInstance(parentProject, "u", "a'b;c", parentProject.FullPath)); itemBag.Add(new ProjectItemInstance(parentProject, "v", "a", parentProject.FullPath)); itemBag.Add(new ProjectItemInstance(parentProject, "w", "1", parentProject.FullPath)); itemBag.Add(new ProjectItemInstance(parentProject, "x", "true", parentProject.FullPath)); itemBag.Add(new ProjectItemInstance(parentProject, "y", "xxx", parentProject.FullPath)); itemBag.Add(new ProjectItemInstance(parentProject, "z", "xxx", parentProject.FullPath)); itemBag.Add(new ProjectItemInstance(parentProject, "z", "yyy", parentProject.FullPath)); PropertyDictionary <ProjectPropertyInstance> propertyBag = new PropertyDictionary <ProjectPropertyInstance>(); propertyBag.Set(ProjectPropertyInstance.Create("a", "no")); propertyBag.Set(ProjectPropertyInstance.Create("b", "true")); propertyBag.Set(ProjectPropertyInstance.Create("c", "1")); propertyBag.Set(ProjectPropertyInstance.Create("d", "xxx")); propertyBag.Set(ProjectPropertyInstance.Create("e", "xxx")); propertyBag.Set(ProjectPropertyInstance.Create("f", "1.9.5")); propertyBag.Set(ProjectPropertyInstance.Create("and", "and")); propertyBag.Set(ProjectPropertyInstance.Create("a_semi_c", "a;c")); propertyBag.Set(ProjectPropertyInstance.Create("a_apos_b", "a'b")); propertyBag.Set(ProjectPropertyInstance.Create("foo_apos_foo", "foo'foo")); propertyBag.Set(ProjectPropertyInstance.Create("a_escapedsemi_b", "a%3bb")); propertyBag.Set(ProjectPropertyInstance.Create("a_escapedapos_b", "a%27b")); propertyBag.Set(ProjectPropertyInstance.Create("has_trailing_slash", @"foo\")); Dictionary <string, string> metadataDictionary = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); metadataDictionary["Culture"] = "french"; StringMetadataTable itemMetadata = new StringMetadataTable(metadataDictionary); _expander = new Expander <ProjectPropertyInstance, ProjectItemInstance>(propertyBag, itemBag, itemMetadata, FileSystems.Default); foreach (string file in FilesWithExistenceChecks) { using (StreamWriter sw = File.CreateText(file)) {; } } }
/// <summary> /// Sets the given property in the given property group. /// </summary> private void SetProperty(ToolsetPropertyDefinition property, PropertyDictionary <ProjectPropertyInstance> propertyGroup, PropertyDictionary <ProjectPropertyInstance> globalProperties) { try { // Global properties cannot be overwritten if (globalProperties[property.Name] == null) { propertyGroup.Set(ProjectPropertyInstance.Create(property.Name, EscapingUtilities.UnescapeAll(property.Value), true /* may be reserved */, false /* not immutable */)); } } catch (ArgumentException ex) { InvalidToolsetDefinitionException.Throw(ex, "InvalidPropertyNameInToolset", property.Name, property.Source.LocationString, ex.Message); } }
public void EqualsSameStartEnd2() { MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Mutable; PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(comparer); ProjectPropertyInstance p1 = ProjectPropertyInstance.Create("a", "value1"); ProjectPropertyInstance p2 = ProjectPropertyInstance.Create("b", "value2"); dictionary.Set(p1); dictionary.Set(p2); ProjectPropertyInstance value = comparer.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, "aabaa", 2, 2); Assert.True(Object.ReferenceEquals(p2, value)); // "Should have returned the 'b' value" }
/// <summary> /// Creates a standard ProjectCollection and adds a fake toolset with the following contents to it: /// /// ToolsVersion = Fake /// Base Properties: /// a = a1 /// b = b1 /// /// SubToolset "12.0": /// d = d4 /// e = e5 /// /// SubToolset "v11.0": /// b = b2 /// c = c2 /// /// SubToolset "FakeSubToolset": /// a = a3 /// c = c3 /// /// SubToolset "v13.0": /// f = f6 /// g = g7 /// </summary> private Toolset GetFakeToolset(IDictionary <string, string> globalPropertiesForProjectCollection) { ProjectCollection projectCollection = new ProjectCollection(globalPropertiesForProjectCollection); IDictionary <string, string> properties = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); properties.Add("a", "a1"); properties.Add("b", "b1"); Dictionary <string, SubToolset> subToolsets = new Dictionary <string, SubToolset>(StringComparer.OrdinalIgnoreCase); // SubToolset 12.0 properties PropertyDictionary <ProjectPropertyInstance> subToolset12Properties = new PropertyDictionary <ProjectPropertyInstance>(); subToolset12Properties.Set(ProjectPropertyInstance.Create("d", "d4")); subToolset12Properties.Set(ProjectPropertyInstance.Create("e", "e5")); // SubToolset v11.0 properties PropertyDictionary <ProjectPropertyInstance> subToolset11Properties = new PropertyDictionary <ProjectPropertyInstance>(); subToolset11Properties.Set(ProjectPropertyInstance.Create("b", "b2")); subToolset11Properties.Set(ProjectPropertyInstance.Create("c", "c2")); // FakeSubToolset properties PropertyDictionary <ProjectPropertyInstance> fakeSubToolsetProperties = new PropertyDictionary <ProjectPropertyInstance>(); fakeSubToolsetProperties.Set(ProjectPropertyInstance.Create("a", "a3")); fakeSubToolsetProperties.Set(ProjectPropertyInstance.Create("c", "c3")); // SubToolset v13.0 properties PropertyDictionary <ProjectPropertyInstance> subToolset13Properties = new PropertyDictionary <ProjectPropertyInstance>(); subToolset13Properties.Set(ProjectPropertyInstance.Create("f", "f6")); subToolset13Properties.Set(ProjectPropertyInstance.Create("g", "g7")); subToolsets.Add("12.0", new SubToolset("12.0", subToolset12Properties)); subToolsets.Add("v11.0", new SubToolset("v11.0", subToolset11Properties)); subToolsets.Add("FakeSubToolset", new SubToolset("FakeSubToolset", fakeSubToolsetProperties)); subToolsets.Add("v13.0", new SubToolset("v13.0", subToolset13Properties)); Toolset parentToolset = projectCollection.GetToolset("4.0"); Toolset fakeToolset = new Toolset("Fake", parentToolset.ToolsPath, properties, projectCollection, subToolsets, parentToolset.OverrideTasksPath); projectCollection.AddToolset(fakeToolset); return(fakeToolset); }
public void ProjectPropertyInstanceSerializationTest_Immutable() { var property = ProjectPropertyInstance.Create("p", "v", mayBeReserved: true, isImmutable: true); Assert.Equal(true, property.IsImmutable); TranslationHelpers.GetWriteTranslator().Translate(ref property, ProjectPropertyInstance.FactoryForDeserialization); ProjectPropertyInstance deserializedProperty = null; TranslationHelpers.GetReadTranslator().Translate(ref deserializedProperty, ProjectPropertyInstance.FactoryForDeserialization); Assert.Equal(property.Name, deserializedProperty.Name); Assert.Equal(property.EvaluatedValue, deserializedProperty.EvaluatedValue); Assert.Equal(property.IsImmutable, deserializedProperty.IsImmutable); Assert.Equal("Microsoft.Build.Execution.ProjectPropertyInstance+ProjectPropertyInstanceImmutable", property.GetType().ToString()); }
public void NotTests() { Console.WriteLine("NegationParseTest()"); Parser p = new Parser(); PropertyDictionary<ProjectPropertyInstance> propertyBag = new PropertyDictionary<ProjectPropertyInstance>(); propertyBag.Set(ProjectPropertyInstance.Create("foo", "4")); propertyBag.Set(ProjectPropertyInstance.Create("bar", "32")); Expander<ProjectPropertyInstance, ProjectItemInstance> expander = new Expander<ProjectPropertyInstance, ProjectItemInstance>(propertyBag, new ItemDictionary<ProjectItemInstance>()); AssertParseEvaluate(p, "!true", expander, false); AssertParseEvaluate(p, "!(true)", expander, false); AssertParseEvaluate(p, "!($(foo) <= 5)", expander, false); AssertParseEvaluate(p, "!($(foo) <= 5 and $(bar) >= 15)", expander, false); }
public void ProjectPropertyInstanceSerializationTest_Mutable() { var property = ProjectPropertyInstance.Create("p", "v", false /*mutable*/); Assert.Equal(false, property.IsImmutable); TranslationHelpers.GetWriteTranslator().Translate(ref property, ProjectPropertyInstance.FactoryForDeserialization); ProjectPropertyInstance deserializedProperty = null; TranslationHelpers.GetReadTranslator().Translate(ref deserializedProperty, ProjectPropertyInstance.FactoryForDeserialization); Assert.Equal(property.Name, deserializedProperty.Name); Assert.Equal(property.EvaluatedValue, deserializedProperty.EvaluatedValue); Assert.Equal(property.IsImmutable, deserializedProperty.IsImmutable); Assert.Equal(typeof(ProjectPropertyInstance), property.GetType()); }
public void MatchProperty() { MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Default; PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(comparer); ProjectPropertyInstance p = ProjectPropertyInstance.Create("foo", "bar"); dictionary.Set(p); string s = "$(foo)"; ProjectPropertyInstance value = dictionary.GetProperty(s, 2, 4); Assert.True(Object.ReferenceEquals(p, value)); // "Should have returned the same object as was inserted" Assert.Equal(MSBuildNameIgnoreCaseComparer.Default.GetHashCode("foo"), comparer.GetHashCode(s, 2, 3)); }
public void TestTranslation() { var globalProperties = new PropertyDictionary <ProjectPropertyInstance>(); globalProperties["a"] = ProjectPropertyInstance.Create("a", "b"); var initial = new ConfigurationMetadata("path", globalProperties); initial.Translate(TranslationHelpers.GetWriteTranslator()); var copy = ConfigurationMetadata.FactoryForDeserialization(TranslationHelpers.GetReadTranslator()); copy.ProjectFullPath.ShouldBe(initial.ProjectFullPath); copy.ToolsVersion.ShouldBe(initial.ToolsVersion); Assert.Equal(copy.GlobalProperties.GetCopyOnReadEnumerable(), initial.GlobalProperties.GetCopyOnReadEnumerable(), EqualityComparer <ProjectPropertyInstance> .Default); }
public void EqualsEndEnd() { MSBuildNameIgnoreCaseComparer comparer = MSBuildNameIgnoreCaseComparer.Mutable; PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(comparer); ProjectPropertyInstance p1 = ProjectPropertyInstance.Create("aabaaaa", "value1"); ProjectPropertyInstance p2 = ProjectPropertyInstance.Create("baaaa", "value2"); dictionary.Set(p1); dictionary.Set(p2); string constraint = "aabaaa"; ProjectPropertyInstance p3 = ProjectPropertyInstance.Create("abaaa", "value3"); dictionary.Set(p3); // Should match o3 ProjectPropertyInstance value1 = comparer.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, constraint, 1, 5); Assert.True(Object.ReferenceEquals(p3, value1)); // "Should have returned the 'abaaa' value" dictionary.Remove("abaaa"); // get rid of o3 ProjectPropertyInstance value2 = comparer.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, constraint, 1, 5); Assert.Null(value2); // "Should not have been a match in the dictionary" // Even if the string is exactly the same, if only a substring is being compared, then although it // will be judged equal, the hash codes will NOT be the same, and for that reason, a lookup in the // dictionary will fail. int originalHashCode = comparer.GetHashCode("aabaaa"); try { comparer.SetConstraintsForUnitTestingOnly(constraint, 1, 5); Assert.True(comparer.Equals("aabaaa", constraint)); // same on both sides Assert.NotEqual(originalHashCode, comparer.GetHashCode(constraint)); } finally { comparer.RemoveConstraintsForUnitTestingOnly(); } }
private static PropertyDictionary <ProjectPropertyInstance> CreatePropertyDictionary(IDictionary <string, string> properties) { PropertyDictionary <ProjectPropertyInstance> propertyDictionary; if (properties == null) { propertyDictionary = new PropertyDictionary <ProjectPropertyInstance>(0); } else { propertyDictionary = new PropertyDictionary <ProjectPropertyInstance>(properties.Count); foreach (var entry in properties) { propertyDictionary[entry.Key] = ProjectPropertyInstance.Create(entry.Key, entry.Value); } } return(propertyDictionary); }
public void TestTranslation() { PropertyDictionary <ProjectPropertyInstance> properties = new PropertyDictionary <ProjectPropertyInstance>(); properties.Set(ProjectPropertyInstance.Create("this", "that")); properties.Set(ProjectPropertyInstance.Create("foo", "bar")); BuildRequestData data = new BuildRequestData("file", properties.ToDictionary(), "4.0", new string[0], null); BuildRequestConfiguration config = new BuildRequestConfiguration(data, "2.0"); Assert.Equal(NodePacketType.BuildRequestConfiguration, config.Type); ((ITranslatable)config).Translate(TranslationHelpers.GetWriteTranslator()); INodePacket packet = BuildRequestConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator()); BuildRequestConfiguration deserializedConfig = packet as BuildRequestConfiguration; Assert.Equal(config, deserializedConfig); }
public void PropertyTests() { Parser p = new Parser(); var propertyBag = new PropertyDictionary <ProjectPropertyInstance>(); propertyBag.Set(ProjectPropertyInstance.Create("foo", "true")); propertyBag.Set(ProjectPropertyInstance.Create("bar", "yes")); propertyBag.Set(ProjectPropertyInstance.Create("one", "1")); propertyBag.Set(ProjectPropertyInstance.Create("onepointzero", "1.0")); propertyBag.Set(ProjectPropertyInstance.Create("two", "2")); propertyBag.Set(ProjectPropertyInstance.Create("simple", "simplestring")); propertyBag.Set(ProjectPropertyInstance.Create("complex", "This is a complex string")); propertyBag.Set(ProjectPropertyInstance.Create("c1", "Another (complex) one.")); propertyBag.Set(ProjectPropertyInstance.Create("c2", "Another (complex) one.")); propertyBag.Set(ProjectPropertyInstance.Create("x86", "x86")); propertyBag.Set(ProjectPropertyInstance.Create("no", "no")); Expander <ProjectPropertyInstance, ProjectItemInstance> expander = new Expander <ProjectPropertyInstance, ProjectItemInstance>(propertyBag, new ItemDictionary <ProjectItemInstance>(), FileSystems.Default); AssertParseEvaluate(p, "$(foo)", expander, true); AssertParseEvaluate(p, "!$(foo)", expander, false); // Test properties with strings AssertParseEvaluate(p, "$(simple) == 'simplestring'", expander, true); AssertParseEvaluate(p, "'simplestring' == $(simple)", expander, true); AssertParseEvaluate(p, "'foo' != $(simple)", expander, true); AssertParseEvaluate(p, "'simplestring' == '$(simple)'", expander, true); AssertParseEvaluate(p, "$(simple) == simplestring", expander, true); AssertParseEvaluate(p, "$(x86) == x86", expander, true); AssertParseEvaluate(p, "$(x86)==x86", expander, true); AssertParseEvaluate(p, "x86==$(x86)", expander, true); AssertParseEvaluate(p, "$(c1) == $(c2)", expander, true); AssertParseEvaluate(p, "'$(c1)' == $(c2)", expander, true); AssertParseEvaluate(p, "$(c1) != $(simple)", expander, true); AssertParseEvaluate(p, "$(c1) == $(c2)", expander, true); // Test properties with numbers AssertParseEvaluate(p, "$(one) == $(onepointzero)", expander, true); AssertParseEvaluate(p, "$(one) <= $(two)", expander, true); AssertParseEvaluate(p, "$(two) > $(onepointzero)", expander, true); AssertParseEvaluate(p, "$(one) != $(two)", expander, true); AssertParseEvaluate(p, "'$(no)'==false", expander, true); }
/// <summary> /// Build the same project twice with different global properties /// </summary> public void BuildingTheSameProjectTwiceWithDifferentGlobalProperties() { ProjectPropertyInstance prop1 = ProjectPropertyInstance.Create("prop1", "Value1"); ProjectPropertyInstance prop2 = ProjectPropertyInstance.Create("prop2", "Value2"); PropertyDictionary <ProjectPropertyInstance> group1 = new PropertyDictionary <ProjectPropertyInstance>(); group1.Set(prop1); PropertyDictionary <ProjectPropertyInstance> group2 = new PropertyDictionary <ProjectPropertyInstance>(); group2.Set(prop2); RequestDefinition p1 = CreateNewRequest("1.proj", "2.0", null, group1); RequestDefinition p2 = CreateNewRequest("1.proj", "3.0", null, group2); p1.SubmitBuildRequest(); p1.ValidateBuildResult(); p2.SubmitBuildRequest(); p2.ValidateBuildResult(); }
/// <summary> /// Constructs a graph starting from the given graph entry points, evaluating with the provided project collection. /// </summary> /// <param name="entryPoints">The entry points to use in constructing the graph</param> /// <param name="projectCollection">The collection with which all projects in the graph should be associated. May not be null.</param> /// <param name="projectInstanceFactory"> /// A delegate used for constructing a <see cref="ProjectInstance"/>, called for each /// project created during graph creation. This value can be null, which uses /// a default implementation that calls the ProjectInstance constructor. See the remarks /// on <see cref="ProjectInstanceFactoryFunc"/> for other scenarios. /// </param> /// <exception cref="AggregateException">If the evaluation of any project in the graph fails, the InnerException contains <see cref="InvalidProjectFileException"/> /// If a null reference is returned from <paramref name="projectInstanceFactory"/>, the InnerException contains <see cref="InvalidOperationException"/></exception> /// <exception cref="CircularDependencyException">If the evaluation is successful but the project graph contains a circular dependency</exception> public ProjectGraph( IEnumerable <ProjectGraphEntryPoint> entryPoints, ProjectCollection projectCollection, ProjectInstanceFactoryFunc projectInstanceFactory) { ErrorUtilities.VerifyThrowArgumentNull(projectCollection, nameof(projectCollection)); projectInstanceFactory = projectInstanceFactory ?? DefaultProjectInstanceFactory; _projectInterpretation = ProjectInterpretation.Instance; var entryPointConfigurationMetadata = new List <ConfigurationMetadata>(); foreach (var entryPoint in entryPoints) { var globalPropertyDictionary = CreatePropertyDictionary(entryPoint.GlobalProperties); AddGraphBuildGlobalVariable(globalPropertyDictionary); var configurationMetadata = new ConfigurationMetadata(FileUtilities.NormalizePath(entryPoint.ProjectFile), globalPropertyDictionary); entryPointConfigurationMetadata.Add(configurationMetadata); } var(entryPointNodes, rootNodes, allNodes) = LoadGraph(entryPointConfigurationMetadata, projectCollection, projectInstanceFactory, _projectInterpretation); EntryPointNodes = entryPointNodes; GraphRoots = rootNodes; ProjectNodes = allNodes; _projectNodesTopologicallySorted = new Lazy <IReadOnlyCollection <ProjectGraphNode> >(() => TopologicalSort(GraphRoots, ProjectNodes)); void AddGraphBuildGlobalVariable(PropertyDictionary <ProjectPropertyInstance> globalPropertyDictionary) { if (globalPropertyDictionary.GetProperty(PropertyNames.IsGraphBuild) == null) { globalPropertyDictionary[PropertyNames.IsGraphBuild] = ProjectPropertyInstance.Create(PropertyNames.IsGraphBuild, "true"); } } }
public void MatchProperty() { PropertyDictionary <ProjectPropertyInstance> dictionary = new PropertyDictionary <ProjectPropertyInstance>(); ProjectPropertyInstance p = ProjectPropertyInstance.Create("foo", "bar"); dictionary.Set(p); string s = "$(foo)"; ProjectPropertyInstance value = MSBuildNameIgnoreCaseComparer.Mutable.GetValueWithConstraints <ProjectPropertyInstance>(dictionary, s, 2, 4); Assert.True(Object.ReferenceEquals(p, value)); // "Should have returned the same object as was inserted" try { MSBuildNameIgnoreCaseComparer.Mutable.SetConstraintsForUnitTestingOnly(s, 2, 4); Assert.Equal(MSBuildNameIgnoreCaseComparer.Default.GetHashCode("foo"), MSBuildNameIgnoreCaseComparer.Mutable.GetHashCode(s)); } finally { MSBuildNameIgnoreCaseComparer.Mutable.RemoveConstraintsForUnitTestingOnly(); } }
public void ValidateToolsetTranslation() { PropertyDictionary <ProjectPropertyInstance> buildProperties = new PropertyDictionary <ProjectPropertyInstance>(); buildProperties.Set(ProjectPropertyInstance.Create("a", "a1")); PropertyDictionary <ProjectPropertyInstance> environmentProperties = new PropertyDictionary <ProjectPropertyInstance>(); environmentProperties.Set(ProjectPropertyInstance.Create("b", "b1")); PropertyDictionary <ProjectPropertyInstance> globalProperties = new PropertyDictionary <ProjectPropertyInstance>(); globalProperties.Set(ProjectPropertyInstance.Create("c", "c1")); PropertyDictionary <ProjectPropertyInstance> subToolsetProperties = new PropertyDictionary <ProjectPropertyInstance>(); subToolsetProperties.Set(ProjectPropertyInstance.Create("d", "d1")); Dictionary <string, SubToolset> subToolsets = new Dictionary <string, SubToolset>(StringComparer.OrdinalIgnoreCase); subToolsets.Add("dogfood", new SubToolset("dogfood", subToolsetProperties)); Toolset t = new Toolset("4.0", "c:\\bar", buildProperties, environmentProperties, globalProperties, subToolsets, "c:\\foo", "4.0", new Dictionary <string, List <string> > { ["MSBuildExtensionsPath"] = new List <string> { @"c:\foo" } }); ((INodePacketTranslatable)t).Translate(TranslationHelpers.GetWriteTranslator()); Toolset t2 = Toolset.FactoryForDeserialization(TranslationHelpers.GetReadTranslator()); Assert.Equal(t.ToolsVersion, t2.ToolsVersion); Assert.Equal(t.ToolsPath, t2.ToolsPath); Assert.Equal(t.OverrideTasksPath, t2.OverrideTasksPath); Assert.Equal(t.Properties.Count, t2.Properties.Count); foreach (string key in t.Properties.Keys) { Assert.Equal(t.Properties[key].Name, t2.Properties[key].Name); Assert.Equal(t.Properties[key].EvaluatedValue, t2.Properties[key].EvaluatedValue); } Assert.Equal(t.SubToolsets.Count, t2.SubToolsets.Count); foreach (string key in t.SubToolsets.Keys) { SubToolset subToolset1 = t.SubToolsets[key]; SubToolset subToolset2 = null; if (t2.SubToolsets.TryGetValue(key, out subToolset2)) { Assert.Equal(subToolset1.SubToolsetVersion, subToolset2.SubToolsetVersion); Assert.Equal(subToolset1.Properties.Count, subToolset2.Properties.Count); foreach (string subToolsetPropertyKey in subToolset1.Properties.Keys) { Assert.Equal(subToolset1.Properties[subToolsetPropertyKey].Name, subToolset2.Properties[subToolsetPropertyKey].Name); Assert.Equal(subToolset1.Properties[subToolsetPropertyKey].EvaluatedValue, subToolset2.Properties[subToolsetPropertyKey].EvaluatedValue); } } else { Assert.True(false, $"Sub-toolset {key} was lost in translation."); } } Assert.Equal(t.DefaultOverrideToolsVersion, t2.DefaultOverrideToolsVersion); Assert.NotNull(t2.ImportPropertySearchPathsTable); Assert.Equal(1, t2.ImportPropertySearchPathsTable.Count); Assert.Equal(@"c:\foo", t2.ImportPropertySearchPathsTable["MSBuildExtensionsPath"][0]); }