public void ModifyPropertyInImportedProjectFileAfterRename() { ObjectModelHelpers.DeleteTempProjectDirectory(); // Create temp files on disk for the main project file and the imported project file. string importedProjFilename = ObjectModelHelpers.CreateFileInTempProjectDirectory("imported.proj", @" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <PropertyGroup> <ReferencePath>c:\foobar</ReferencePath> </PropertyGroup> </Project> "); string mainProjFilename = ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", string.Format(@" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <Import Project=`{0}`/> <PropertyGroup> <ConsumingRefPath>$(ReferencePath)</ConsumingRefPath> </PropertyGroup> </Project> ", importedProjFilename)); // Load the two projects using the MSBuild object model. Project mainProj = new Project(new Engine(@"c:\")); Project importedProj = new Project(mainProj.ParentEngine); mainProj.Load(mainProjFilename); importedProj.Load(importedProjFilename); // Initially, the main project gets the correct value of the property from // the imported project. So ConsumingRefPath == "$(ReferencePath)" == "c:\foobar". Assertion.AssertEquals(@"c:\foobar", mainProj.EvaluatedProperties["ConsumingRefPath"].FinalValueEscaped); mainProj.SetImportedProperty("ReferencePath", @"c:\boobah", null, importedProj); // Now if we query for the property, we should get back the new value. Assertion.AssertEquals(@"c:\boobah", mainProj.EvaluatedProperties["ConsumingRefPath"].FinalValueEscaped); Assertion.AssertEquals(@"c:\boobah", importedProj.EvaluatedProperties["ReferencePath"].FinalValueEscaped); importedProj.Save(Path.Combine(ObjectModelHelpers.TempProjectDir, "newimported.proj")); // Now we add a new imported property to the main file, into an existing imported // property group. mainProj.SetImportedProperty("ReferencePath", @"c:\hoohah", null, importedProj); // Now if we query for the property, we should get back the new value. Assertion.AssertEquals(@"c:\hoohah", importedProj.EvaluatedProperties["ReferencePath"].FinalValueEscaped); Assertion.AssertEquals(@"c:\hoohah", mainProj.EvaluatedProperties["ReferencePath"].FinalValueEscaped); }
public void ModifyPropertyInImportedProjectFile() { // Create temp files on disk for the main project file and the imported project file. string importedProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(@" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <PropertyGroup> <ReferencePath>c:\foobar</ReferencePath> </PropertyGroup> </Project> "); string mainProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(@" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <Import Project=`{0}`/> <PropertyGroup> <ConsumingRefPath>$(ReferencePath)</ConsumingRefPath> </PropertyGroup> </Project> ", importedProjFilename); try { // Load the two projects using the MSBuild object model. Project mainProj = new Project(new Engine(@"c:\")); Project importedProj = new Project(mainProj.ParentEngine); mainProj.Load(mainProjFilename); importedProj.Load(importedProjFilename); // Initially, the main project gets the correct value of the property from // the imported project. So ConsumingRefPath == "$(ReferencePath)" == "c:\foobar". Assertion.AssertEquals(@"c:\foobar", mainProj.EvaluatedProperties["ConsumingRefPath"].FinalValueEscaped); Assertion.Assert("Main project should not be dirty for Save before setting imported property", !mainProj.IsDirty); Assertion.Assert("Main project should not be dirty for Evaluation before setting imported property", !mainProj.IsDirtyNeedToReevaluate); Assertion.Assert("Imported project should not be dirty for Save before setting imported property", !importedProj.IsDirty); Assertion.Assert("Imported project should not be dirty for Evaluation before setting imported property", !importedProj.IsDirtyNeedToReevaluate); mainProj.SetImportedProperty("ReferencePath", @"c:\boobah", null, importedProj); Assertion.Assert("Main project should not be dirty for Save after setting first imported property", !mainProj.IsDirty); Assertion.Assert("Main project should be dirty for Evaluation after setting first imported property", mainProj.IsDirtyNeedToReevaluate); Assertion.Assert("Imported project should be dirty for Save after setting first imported property", importedProj.IsDirty); Assertion.Assert("Imported project should be dirty for Evaluation after setting first imported property", importedProj.IsDirtyNeedToReevaluate); // Now if we query for the property, we should get back the new value. Assertion.AssertEquals(@"c:\boobah", mainProj.EvaluatedProperties["ConsumingRefPath"].FinalValueEscaped); Assertion.AssertEquals(@"c:\boobah", importedProj.EvaluatedProperties["ReferencePath"].FinalValueEscaped); // Now we add a new imported property to the main file, into an existing imported // property group. mainProj.SetImportedProperty("NewImportedProperty", @"newpropertyvalue", null, importedProj); // Now if we query for the property, we should get back the new value. Assertion.AssertEquals(@"newpropertyvalue", mainProj.EvaluatedProperties["NewImportedProperty"].FinalValueEscaped); Assertion.AssertEquals(@"newpropertyvalue", importedProj.EvaluatedProperties["NewImportedProperty"].FinalValueEscaped); // Now we add a new imported property to the main file, into a new imported // property group (by setting a unique condition). mainProj.SetImportedProperty("NewImportedPropertyWithCondition", @"anotherpropertyvalue", "'$(foo)' == '$(bar)'", importedProj); // Now if we query for the property, we should get back the new value. Assertion.AssertEquals(@"anotherpropertyvalue", mainProj.EvaluatedProperties["NewImportedPropertyWithCondition"].FinalValueEscaped); Assertion.AssertEquals(@"anotherpropertyvalue", importedProj.EvaluatedProperties["NewImportedPropertyWithCondition"].FinalValueEscaped); Assertion.Assert("Main project should not be dirty for Save after setting last imported property", !mainProj.IsDirty); Assertion.Assert("Imported project should be dirty for Save after setting last imported property", importedProj.IsDirty); } finally { File.Delete(mainProjFilename); File.Delete(importedProjFilename); } }
public void ModifyImportedPropertyGroupCondition() { // Create temp files on disk for the main project file and the imported project file. string importedProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(@" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> </Project> "); string mainProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(@" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <Import Project=`{0}`/> </Project> ", importedProjFilename); try { // Load the two projects using the MSBuild object model. Project mainProj = new Project(new Engine(@"c:\")); Project importedProj = new Project(mainProj.ParentEngine); mainProj.Load(mainProjFilename); importedProj.Load(importedProjFilename); string configCondition1 = "'$(Configuration)' == 'Config1'"; string configCondition2 = "'$(Configuration)' == 'Config2'"; // Add same property to imported user file mainProj.SetImportedProperty("Prop", "FromUserFile", configCondition1, importedProj, PropertyPosition.UseExistingOrCreateAfterLastImport); mainProj.SetImportedProperty("Prop", "FromUserFile", configCondition2, importedProj, PropertyPosition.UseExistingOrCreateAfterLastImport); foreach (BuildPropertyGroup bpg in mainProj.PropertyGroups) { if (bpg.Condition == configCondition2) { bpg.SetImportedPropertyGroupCondition("'$(Configuration)' == 'NewConfig'"); } } string[] configs = mainProj.GetConditionedPropertyValues("Configuration"); Assertion.AssertEquals(2, configs.Length); Assertion.Assert(configs[0] == "Config1" || configs[1] == "Config1"); Assertion.Assert(configs[0] == "NewConfig" || configs[1] == "NewConfig"); } finally { File.Delete(mainProjFilename); File.Delete(importedProjFilename); } }
public void AddPropertyToImportedProjectFile() { // Create temp files on disk for the main project file and the imported project file. string importedProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(@" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> </Project> "); string mainProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(@" <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <PropertyGroup> <NonConsumingRefPath>$(ReferencePath)$(NewImportedProperty)</NonConsumingRefPath> </PropertyGroup> <Import Project=`{0}`/> <PropertyGroup> <ConsumingRefPath>$(ReferencePath)$(NewImportedProperty)</ConsumingRefPath> </PropertyGroup> </Project> ", importedProjFilename); try { // Load the two projects using the MSBuild object model. Project mainProj = new Project(new Engine(@"c:\")); Project importedProj = new Project(mainProj.ParentEngine); mainProj.Load(mainProjFilename); importedProj.Load(importedProjFilename); // This adds a new property mainProj.SetImportedProperty("ReferencePath", @"c:\foobar", "'true' == 'true'", importedProj); // Initially, the main project gets the correct value of the property from // the imported project. So ConsumingRefPath == "$(ReferencePath)" == "c:\foobar". Assertion.AssertEquals(@"c:\foobar", mainProj.EvaluatedProperties["ConsumingRefPath"].FinalValueEscaped); Assertion.AssertEquals(string.Empty, mainProj.EvaluatedProperties["NonConsumingRefPath"].FinalValueEscaped); mainProj.SetImportedProperty("ReferencePath", @"c:\boobah", "'true' == 'true'", importedProj); // Now if we query for the property, we should get back the new value. Assertion.AssertEquals(@"c:\boobah", mainProj.EvaluatedProperties["ConsumingRefPath"].FinalValueEscaped); Assertion.AssertEquals(@"c:\boobah", importedProj.EvaluatedProperties["ReferencePath"].FinalValueEscaped); Assertion.AssertEquals(string.Empty, mainProj.EvaluatedProperties["NonConsumingRefPath"].FinalValueEscaped); // Now we add a new imported property to the main file, into an existing imported // property group. mainProj.SetImportedProperty("NewImportedProperty", @"newpropertyvalue", "'true' == 'true'", importedProj); // Now if we query for the property, we should get back the new value. Assertion.AssertEquals(@"newpropertyvalue", mainProj.EvaluatedProperties["NewImportedProperty"].FinalValueEscaped); Assertion.AssertEquals(@"newpropertyvalue", importedProj.EvaluatedProperties["NewImportedProperty"].FinalValueEscaped); Assertion.AssertEquals(@"c:\boobahnewpropertyvalue", mainProj.EvaluatedProperties["ConsumingRefPath"].FinalValueEscaped); Assertion.AssertEquals(string.Empty, mainProj.EvaluatedProperties["NonConsumingRefPath"].FinalValueEscaped); } finally { File.Delete(mainProjFilename); File.Delete(importedProjFilename); } }
public void SetImportedPropertyCondition_Null() { string importedProjFilename = String.Empty; string mainProjFilename = String.Empty; try { importedProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(TestData.PropertyGroup); mainProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(TestData.Content3SimpleTargetsDefaultSpecified); Project mainProject = new Project(new Engine()); Project importedProject = new Project(mainProject.ParentEngine); mainProject.Load(mainProjFilename); importedProject.Load(importedProjFilename); mainProject.SetImportedProperty("n1", "newV", null, importedProject); Assertion.AssertEquals("newV", importedProject.GetEvaluatedProperty("n1")); } finally { CompatibilityTestHelpers.RemoveFile(importedProjFilename); CompatibilityTestHelpers.RemoveFile(mainProjFilename); } }
public void SetPropertySetValueLiteralFlag() { string importedProjFilename = String.Empty; string mainProjFilename = String.Empty; try { importedProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(TestData.PropertyGroup); mainProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(TestData.Content3SimpleTargetsDefaultSpecified); Project mainProject = new Project(new Engine()); Project importedProject = new Project(mainProject.ParentEngine); mainProject.Load(mainProjFilename); importedProject.Load(importedProjFilename); mainProject.SetImportedProperty("n1", "newV", "true", importedProject, PropertyPosition.UseExistingOrCreateAfterLastImport, true); mainProject.SetImportedProperty("literalFalse", @"%25%2a%3f%40%24%28%29%3b\", "true", importedProject, PropertyPosition.UseExistingOrCreateAfterLastImport, false); mainProject.SetImportedProperty("literalTrue", @"%25%2a%3f%40%24%28%29%3b\", "true", importedProject, PropertyPosition.UseExistingOrCreateAfterLastImport, true); mainProject.SetImportedProperty("nonLiteralFalse", @"%*?@$();\", "true", importedProject, PropertyPosition.UseExistingOrCreateAfterLastImport, false); mainProject.SetImportedProperty("nonLiteralTrue", @"%*?@$();\", "true", importedProject, PropertyPosition.UseExistingOrCreateAfterLastImport, true); Assertion.AssertEquals(@"%*?@$();\", mainProject.GetEvaluatedProperty("literalFalse")); Assertion.AssertEquals(@"%*?@$();\", mainProject.GetEvaluatedProperty("nonLiteralTrue")); Assertion.AssertEquals(@"%25%2a%3f%40%24%28%29%3b\", mainProject.GetEvaluatedProperty("literalTrue")); Assertion.AssertEquals(@"%*?@;\", mainProject.GetEvaluatedProperty("nonLiteralFalse")); } finally { CompatibilityTestHelpers.RemoveFile(importedProjFilename); CompatibilityTestHelpers.RemoveFile(mainProjFilename); } }
public void RemovePropertyGroupsWithMatchingConditionMatchInImported_True() { string importedProjFilename = String.Empty; string mainProjFilename = String.Empty; try { importedProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(TestData.PropertyGroup); mainProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(TestData.Content3SimpleTargetsDefaultSpecified); Project mainProject = new Project(new Engine()); Project importedProject = new Project(mainProject.ParentEngine); mainProject.Load(mainProjFilename); importedProject.Load(importedProjFilename); BuildPropertyGroup referenceGroup = mainProject.AddNewPropertyGroup(true); referenceGroup.Condition = "true"; mainProject.SetImportedProperty("newp", "newv", "true", importedProject); Assertion.AssertEquals(2, mainProject.PropertyGroups.Count); mainProject.RemovePropertyGroupsWithMatchingCondition("true", true); Assertion.AssertEquals(0, mainProject.PropertyGroups.Count); } finally { CompatibilityTestHelpers.RemoveFile(importedProjFilename); CompatibilityTestHelpers.RemoveFile(mainProjFilename); } }
public void RemoveImportedPropertyGroup() { string importedProjFilename = String.Empty; string mainProjFilename = String.Empty; try { importedProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(TestData.PropertyGroup); mainProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(TestData.Content3SimpleTargetsDefaultSpecified); Project mainProject = new Project(new Engine()); Project importedProject = new Project(mainProject.ParentEngine); mainProject.SetImportedProperty("property", "value", "true", importedProject); mainProject.Load(mainProjFilename); } finally { CompatibilityTestHelpers.RemoveFile(importedProjFilename); CompatibilityTestHelpers.RemoveFile(mainProjFilename); } }