public void ModifyPersistedImportedPropertyGroupCondition() { // 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> </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); foreach (BuildPropertyGroup bpg in mainProj.PropertyGroups) { if (bpg.Condition == "'$(Configuration)' == 'Config2'") { 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 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 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 GetConditionedPropertyValues_Missing() { Project p = new Project(); string[] values = p.GetConditionedPropertyValues("doesnotExist"); Assertion.AssertEquals(0, values.Length); }
public void GetConditionedPropertyValues_EmptyString() { Project p = new Project(); string[] values = p.GetConditionedPropertyValues(String.Empty); Assertion.AssertEquals(0, values.Length); }
public void GetConditionedPropertyValues_Null() { Project p = new Project(); string[] values = p.GetConditionedPropertyValues(null); }