本文整理汇总了C#中Microsoft.Build.BuildEngine.Project.SetImportedProperty方法的典型用法代码示例。如果您正苦于以下问题:C# Project.SetImportedProperty方法的具体用法?C# Project.SetImportedProperty怎么用?C# Project.SetImportedProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.BuildEngine.Project
的用法示例。
在下文中一共展示了Project.SetImportedProperty方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModifyPropertyInImportedProjectFileAfterRename
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);
}
示例2: ModifyPropertyInImportedProjectFile
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);
}
}
示例3: ModifyImportedPropertyGroupCondition
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);
}
}
示例4: AddPropertyToImportedProjectFile
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);
}
}
示例5: SetImportedPropertyCondition_Null
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);
}
}
示例6: SetPropertySetValueLiteralFlag
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", @"%*[email protected]$();\", "true", importedProject, PropertyPosition.UseExistingOrCreateAfterLastImport, false);
mainProject.SetImportedProperty("nonLiteralTrue", @"%*[email protected]$();\", "true", importedProject, PropertyPosition.UseExistingOrCreateAfterLastImport, true);
Assertion.AssertEquals(@"%*[email protected]$();\", mainProject.GetEvaluatedProperty("literalFalse"));
Assertion.AssertEquals(@"%*[email protected]$();\", mainProject.GetEvaluatedProperty("nonLiteralTrue"));
Assertion.AssertEquals(@"%25%2a%3f%40%24%28%29%3b\", mainProject.GetEvaluatedProperty("literalTrue"));
Assertion.AssertEquals(@"%*[email protected];\", mainProject.GetEvaluatedProperty("nonLiteralFalse"));
}
finally
{
CompatibilityTestHelpers.RemoveFile(importedProjFilename);
CompatibilityTestHelpers.RemoveFile(mainProjFilename);
}
}
示例7: RemovePropertyGroupsWithMatchingConditionMatchInImported_True
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);
}
}
示例8: RemoveImportedPropertyGroup
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);
}
}