当前位置: 首页>>代码示例>>C#>>正文


C# Project.SetImportedProperty方法代码示例

本文整理汇总了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);
        }
开发者ID:nikson,项目名称:msbuild,代码行数:58,代码来源:Project_Tests.cs

示例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);
            }
        }
开发者ID:nikson,项目名称:msbuild,代码行数:83,代码来源:Project_Tests.cs

示例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);
            }
        }
开发者ID:nikson,项目名称:msbuild,代码行数:57,代码来源:Project_Tests.cs

示例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);
            }
        }
开发者ID:nikson,项目名称:msbuild,代码行数:68,代码来源:Project_Tests.cs

示例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);
     }
 }
开发者ID:nikson,项目名称:msbuild,代码行数:21,代码来源:Project_Tests.cs

示例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);
                }
            }
开发者ID:nikson,项目名称:msbuild,代码行数:29,代码来源:Project_Tests.cs

示例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);
     }
 }
开发者ID:nikson,项目名称:msbuild,代码行数:25,代码来源:Project_Tests.cs

示例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);
     }
 }
开发者ID:nikson,项目名称:msbuild,代码行数:19,代码来源:Project_Tests.cs


注:本文中的Microsoft.Build.BuildEngine.Project.SetImportedProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。