public void RemovePersistedImportedPropertyGroupMatchingCondition() { // 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 Condition=`'$(Configuration)' == 'Config1'`> <Prop>FromUserFile1</Prop> </PropertyGroup> <PropertyGroup Condition=`'$(Configuration)' == 'Config2'`> <Prop>FromUserFile2</Prop> </PropertyGroup> <PropertyGroup Condition=`'$(Configuration)' == 'Test'`> <Prop>FromUserFileTest</Prop> </PropertyGroup> </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); mainProj.RemovePropertyGroupsWithMatchingCondition("'$(Configuration)' == 'Test'", true /* include imported */); importedProj.RemovePropertyGroupsWithMatchingCondition("'$(Configuration)' == 'Test'", true /* include imported */); string[] configs = mainProj.GetConditionedPropertyValues("Configuration"); Assertion.AssertEquals(2, configs.Length); Assertion.Assert(configs[0] == "Config1" || configs[1] == "Config1"); Assertion.Assert(configs[0] == "Config2" || configs[1] == "Config2"); } finally { File.Delete(mainProjFilename); File.Delete(importedProjFilename); } }
public void RemovePropertyGroupsWithMatchingCondition_MatchInProject() { string mainProjFilename = String.Empty; try { mainProjFilename = ObjectModelHelpers.CreateTempFileOnDisk(TestData.PropertyGroup); Project mainProject = new Project(new Engine()); mainProject.Load(mainProjFilename); Assertion.AssertEquals(1, mainProject.PropertyGroups.Count); mainProject.RemovePropertyGroupsWithMatchingCondition("true"); Assertion.AssertEquals(0, mainProject.PropertyGroups.Count); } finally { CompatibilityTestHelpers.RemoveFile(mainProjFilename); } }
public void RemoveImportedPropertyGroupMatchingCondition() { // 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'"; string configTestCondition = "'$(Configuration)' == 'Test'"; // Add same property to imported user file mainProj.SetImportedProperty("Prop", "FromUserFile", configCondition1, importedProj, PropertyPosition.UseExistingOrCreateAfterLastImport); mainProj.SetImportedProperty("Prop", "FromUserFile", configCondition2, importedProj, PropertyPosition.UseExistingOrCreateAfterLastImport); mainProj.SetImportedProperty("Prop", "FromUserFile", configTestCondition, importedProj, PropertyPosition.UseExistingOrCreateAfterLastImport); mainProj.RemovePropertyGroupsWithMatchingCondition(configTestCondition, true /* include imported */); importedProj.RemovePropertyGroupsWithMatchingCondition(configTestCondition, true /* include imported */); string[] configs = mainProj.GetConditionedPropertyValues("Configuration"); Assertion.AssertEquals(2, configs.Length); Assertion.Assert(configs[0] == "Config1" || configs[1] == "Config1"); Assertion.Assert(configs[0] == "Config2" || configs[1] == "Config2"); } finally { File.Delete(mainProjFilename); File.Delete(importedProjFilename); } }
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); } }