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


C# Engine.AddToolset方法代码示例

本文整理汇总了C#中Microsoft.Build.BuildEngine.Engine.AddToolset方法的典型用法代码示例。如果您正苦于以下问题:C# Engine.AddToolset方法的具体用法?C# Engine.AddToolset怎么用?C# Engine.AddToolset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Build.BuildEngine.Engine的用法示例。


在下文中一共展示了Engine.AddToolset方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddingAnExistingToolsVersionDirtiesLoadedProjects

        public void AddingAnExistingToolsVersionDirtiesLoadedProjects()
        {
            try
            {
                Engine e = new Engine(ToolsetDefinitionLocations.None);
                e.AddToolset(new Toolset("2.0", "someToolsPath"));
                e.AddToolset(new Toolset("3.0", "anotherToolsPath"));

                string p1Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("p1.csproj", @"<Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`/>");
                string p2Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("p2.csproj", @"<Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`/>");

                Project p1 = new Project(e, "2.0");
                p1.Load(p1Path);
                Project p2 = new Project(e, "3.0");
                p2.Load(p2Path);

                Assertion.Assert("Expected p1.IsDirty to be false", !p1.IsDirty);
                Assertion.Assert("Expected p2.IsDirty to be false", !p2.IsDirty);

                e.AddToolset(new Toolset("2.0", "someTotallyDifferentToolsPath"));

                Assertion.Assert("Expected p1.IsDirty to be true", p1.IsDirty);
                Assertion.Assert("Expected p2.IsDirty to be false", !p2.IsDirty);

            }
            finally
            {
                ObjectModelHelpers.DeleteTempProjectDirectory();
            }
        }
开发者ID:nikson,项目名称:msbuild,代码行数:30,代码来源:Engine_Tests.cs

示例2: BinPathAfterDefaultToolsVersionChange

 public void BinPathAfterDefaultToolsVersionChange()
 {
     Engine e = new Engine(ToolsetDefinitionLocations.None);
     e.AddToolset(new Toolset("orcas", @"C:\OrcasBinPath"));
     e.DefaultToolsVersion = "Orcas";
     Assertion.AssertEquals(@"C:\OrcasBinPath", e.BinPath);
     Assertion.AssertEquals("Orcas", e.DefaultToolsVersion);
 }
开发者ID:nikson,项目名称:msbuild,代码行数:8,代码来源:Engine_Tests.cs

示例3: ToolsVersionAttributeNotSpecifiedOnProjectElementAndDefaultVersionSpecifiedInRegistry

        public void ToolsVersionAttributeNotSpecifiedOnProjectElementAndDefaultVersionSpecifiedInRegistry()
        {
            Engine e = new Engine();
            e.AddToolset(new Toolset("2.0", "20toolsPath"));
            e.AddToolset(new Toolset("4.0", "40toolsPath"));

            string projectPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("x.proj", @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" />");

            Project project = e.CreateNewProject();
            project.Load(projectPath);

            Assertion.AssertEquals("2.0", project.ToolsVersion);
            Assertion.AssertEquals("2.0", project.DefaultToolsVersion);
        }
开发者ID:nikson,项目名称:msbuild,代码行数:14,代码来源:ToolsetReader_Tests.cs

示例4: SettingDefaultToolsVersionThrowsIfProjectsAlreadyLoaded

        public void SettingDefaultToolsVersionThrowsIfProjectsAlreadyLoaded()
        {
            Engine e = new Engine(ToolsetDefinitionLocations.None);
            
            try
            {
                e.AddToolset(new Toolset("1.0", "someToolsPath"));
                e.AddToolset(new Toolset("2.0", "someToolsPath"));
                e.DefaultToolsVersion = "1.0"; // OK
            }
            catch(InvalidOperationException)
            {
                // Make sure the first one doesn't throw
                Assertion.Assert(false); 
            }

            try
            {
                string p1Path = ObjectModelHelpers.CreateFileInTempProjectDirectory("p1.csproj", @"<Project DefaultTargets=`Build` xmlns=`msbuildnamespace`/>");
                Project p1 = new Project(e);
                p1.Load(p1Path);

                e.DefaultToolsVersion = "2.0"; // Throws
            }
            finally
            {
                ObjectModelHelpers.DeleteTempProjectDirectory();
            }
        }
开发者ID:nikson,项目名称:msbuild,代码行数:29,代码来源:Engine_Tests.cs

示例5: SetEffectiveToolsVersionAttribute

        public void SetEffectiveToolsVersionAttribute()
        {
            Engine e = new Engine("www.msbuild.org");
            e.AddToolset(new Toolset("myValidToolsVersion", "myValidToolsVersion's path"));
            e.AddToolset(new Toolset("myOtherToolsVersion", "myOtherToolsVersion's path"));

            MockLogger logger = new MockLogger();

            Project project = ObjectModelHelpers.CreateInMemoryProject(e, ObjectModelHelpers.CleanupFileContents(@"
                <Project ToolsVersion=`myValidToolsVersion` DefaultTargets=`Build` xmlns=`msbuildnamespace`>
                    <UsingTask TaskName='Message' AssemblyName='Microsoft.Build.Tasks.Core, Version=msbuildassemblyversion, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'/>    
                    <PropertyGroup>
                       <TheToolsVersion>$(MSBuildToolsVersion)</TheToolsVersion>
                    </PropertyGroup>
                    <Target Name=`Build`>
                       <Message Text=`### $(TheToolsVersion) ###` />
                    </Target>
                </Project>"), logger, "myValidToolsVersion");

            project.ToolsVersion = "myOtherToolsVersion";

            project.Build();

            Assertion.Assert("We should be using a ToolsVersion override", project.OverridingToolsVersion);
            Assertion.AssertEquals("We should have ToolsVersion equal to myOtherToolsVersion",
                "myOtherToolsVersion", project.ToolsVersion);
            Assertion.AssertEquals("We should have ToolsVersionAttribute equal to myValidToolsVersion",
                "myValidToolsVersion", project.DefaultToolsVersion);
            logger.AssertLogContains("### myOtherToolsVersion ###");
        }
开发者ID:nikson,项目名称:msbuild,代码行数:30,代码来源:Project_Tests.cs

示例6: PropertiesFromToolsetAppliedToProjectWhenToolsVersionOverridden

        public void PropertiesFromToolsetAppliedToProjectWhenToolsVersionOverridden()
        {
            Engine e = new Engine("www.msbuild.org");
            BuildPropertyGroup properties1 = new BuildPropertyGroup();
            properties1.SetProperty("foo1", "bar1");
            properties1.SetProperty("foo2", "bar2");
            BuildPropertyGroup properties2 = new BuildPropertyGroup();
            properties2.SetProperty("foo3", "bar3");
            properties2.SetProperty("foo1", "bar4");
            e.AddToolset(new Toolset("myValidToolsVersion", "myValidToolsVersion's path", properties1));
            e.AddToolset(new Toolset("myOtherToolsVersion", "myOtherToolsVersion's path", properties2));

            MockLogger logger = new MockLogger();

            Project project = ObjectModelHelpers.CreateInMemoryProject(e, @"
                <Project ToolsVersion=`myValidToolsVersion` xmlns=`msbuildnamespace`/>", logger, "myOtherToolsVersion");

            Assertion.AssertEquals("bar4", project.EvaluatedProperties["foo1"].Value);  // Updated
            Assertion.AssertEquals(null, project.EvaluatedProperties["foo2"]);      // Reset
            Assertion.AssertEquals("bar3", project.EvaluatedProperties["foo3"].Value);  // New
        }
开发者ID:nikson,项目名称:msbuild,代码行数:21,代码来源:Project_Tests.cs

示例7: SettingToolsVersionAttributeAfterToolsVersionSetInProjectConstructor

        public void SettingToolsVersionAttributeAfterToolsVersionSetInProjectConstructor()
        {
            Engine e = new Engine("www.msbuild.org");
            e.AddToolset(new Toolset("myValidToolsVersion", "myValidToolsVersion's path"));
            e.AddToolset(new Toolset("myOtherToolsVersion", "myOtherToolsVersion's path"));

            Project project = ObjectModelHelpers.CreateInMemoryProject(e, @"
                <Project DefaultTargets=`Build` xmlns=`msbuildnamespace`>
                    <Target Name=`Build`/>
                </Project>", null, "myValidToolsVersion");

            project.DefaultToolsVersion = "myOtherToolsVersion";

            Assertion.AssertEquals("We should have Override equal to true",
                true, project.OverridingToolsVersion);
            Assertion.AssertEquals("We should have ToolsVersion equal to myOtherToolsVersion",
                "myValidToolsVersion", project.ToolsVersion);
            Assertion.AssertEquals("We should have ToolsVersionAttribute equal to myOtherToolsVersion",
                "myOtherToolsVersion", project.DefaultToolsVersion);
        }
开发者ID:nikson,项目名称:msbuild,代码行数:20,代码来源:Project_Tests.cs

示例8: MSBuildToolsVersionProperty2

        public void MSBuildToolsVersionProperty2()
        {
            Engine e = new Engine("www.msbuild.org");
            e.AddToolset(new Toolset("myValidToolsVersion", "myValidToolsVersion's path"));

            MockLogger logger = new MockLogger();

            Project project = ObjectModelHelpers.CreateInMemoryProject(e, ObjectModelHelpers.CleanupFileContents(@"
                <Project DefaultTargets=`Build` xmlns=`msbuildnamespace`>
                    <UsingTask TaskName='Message' AssemblyName='Microsoft.Build.Tasks.Core, Version=msbuildassemblyversion, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'/>    
                    <Target Name=`Build`>
                        <Message Text=`##$(MSBuildToolsVersion)##`/>
                    </Target>
                </Project>"), logger);
            project.DefaultToolsVersion = "myValidToolsVersion";

            project.Build();

            logger.AssertLogContains("##myValidToolsVersion##");
        }
开发者ID:nikson,项目名称:msbuild,代码行数:20,代码来源:Project_Tests.cs

示例9: ChangingToolsVersionAttributeToUnrecognizedValue

        public void ChangingToolsVersionAttributeToUnrecognizedValue()
        {
            Engine e = new Engine("www.msbuild.org");
            e.AddToolset(new Toolset("myValidToolsVersion", "myValidToolsVersion's path"));

            Project project = ObjectModelHelpers.CreateInMemoryProject(e, @"
                <Project ToolsVersion=`myValidToolsVersion` DefaultTargets=`Build` xmlns=`msbuildnamespace`>
                    <Target Name=`Build`/>
                </Project>", null);

            Assertion.AssertEquals("We should have toolsVersion equal to myValidToolsVersion",
                "myValidToolsVersion", project.DefaultToolsVersion);

            // Build should succeed at this point
            Assertion.Assert(project.Build());

            project.DefaultToolsVersion = "UnknownToolsVersion";

            // When an unknown toolsversion is used, MSBuild treats it as TV4.0.
            Assertion.AssertEquals("Because a bogus ToolsVersion was set, the ToolsVersion gets treated as v4.0", "4.0", project.ToolsVersion);

            Assertion.AssertEquals("ToolsVersionAttribute has the new value", "4.0", project.DefaultToolsVersion);

            // It's a valid ToolsVersion, so the build should succeed
            Assertion.Assert(project.Build());
        }
开发者ID:nikson,项目名称:msbuild,代码行数:26,代码来源:Project_Tests.cs

示例10: ChangingToolsVersion

        public void ChangingToolsVersion()
        {
            Engine e = new Engine("www.msbuild.org");
            e.AddToolset(new Toolset("myValidToolsVersion", "myValidToolsVersion's path"));

            Project project = ObjectModelHelpers.CreateInMemoryProject(e, @"
                <Project DefaultTargets=`Build` xmlns=`msbuildnamespace`>
                    <Target Name=`Build`/>
                </Project>", null);

            Assertion.AssertEquals("Nonexistent ToolsVersion should evaluate to the default version",
                Constants.defaultToolsVersion, project.ToolsVersion);

            Assertion.AssertEquals("BinPath is the MSBuildBinPath for the default version",
                "www.msbuild.org", project.EvaluatedProperties[ReservedPropertyNames.binPath].FinalValue);

            Assertion.AssertEquals("BinPath is the MSBuildToolsPath for the default version",
                "www.msbuild.org", project.EvaluatedProperties[ReservedPropertyNames.toolsPath].FinalValue);

            project.DefaultToolsVersion = "myValidToolsVersion";

            Assertion.AssertEquals("ToolsVersion should have been changed by the project attribute (because it wasn't overridden)",
                "myValidToolsVersion", project.ToolsVersion);

            Assertion.AssertEquals("ToolsVersionAttribute should have been picked up from the project attribute",
                "myValidToolsVersion", project.DefaultToolsVersion);

            Assertion.AssertEquals("OverridingToolsVersion should be false",
                false, project.OverridingToolsVersion);

            Assertion.AssertEquals("BinPath is the MSBuildBinPath for the default version",
                "myValidToolsVersion's path", project.EvaluatedProperties[ReservedPropertyNames.binPath].FinalValue);

            Assertion.AssertEquals("BinPath is the MSBuildToolsPath for the default version",
                "myValidToolsVersion's path", project.EvaluatedProperties[ReservedPropertyNames.toolsPath].FinalValue);
        }
开发者ID:nikson,项目名称:msbuild,代码行数:36,代码来源:Project_Tests.cs

示例11: VersionBasedMSBuildBinPathExplicit

        public void VersionBasedMSBuildBinPathExplicit()
        {
            Engine e = new Engine("www.msbuild.org");
            e.AddToolset(new Toolset("myValidToolsVersion", "myValidToolsVersion's path"));

            Project project = ObjectModelHelpers.CreateInMemoryProject(e, @"
                <Project ToolsVersion=`myValidToolsVersion` DefaultTargets=`Build` xmlns=`msbuildnamespace`>
                    <Target Name=`Build`/>
                </Project>", null);

            Assertion.AssertEquals("ToolsVersion should have been picked up from the project attribute", 
                "myValidToolsVersion", project.ToolsVersion);

            Assertion.AssertEquals("ToolsVersionAttribute should have been picked up from the project attribute",
                "myValidToolsVersion", project.DefaultToolsVersion);

            Assertion.AssertEquals("BinPath is the MSBuildBinPath for the default version",
                "myValidToolsVersion's path", project.EvaluatedProperties[ReservedPropertyNames.binPath].FinalValue);

            Assertion.AssertEquals("BinPath is the MSBuildToolsPath for the default version",
                "myValidToolsVersion's path", project.EvaluatedProperties[ReservedPropertyNames.toolsPath].FinalValue);
        }
开发者ID:nikson,项目名称:msbuild,代码行数:22,代码来源:Project_Tests.cs

示例12: ToolsVersionRespectedWhenBuildingASolution

        public void ToolsVersionRespectedWhenBuildingASolution()
        {
            ObjectModelHelpers.DeleteTempProjectDirectory();

            Engine engine = new Engine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath));

            // We've intentionally assigned the correct BinPath value to the tools version '3.5' since later
            // we will request the engine build the solution with that tools version, and the engine will
            // need to locate the default tasks. If the override we're going to specify isn't in fact applied,
            // the engine will try to load the tasks from the bogus toolpath, and that will fail the solution build,
            // so this test will fail.
            engine.AddToolset(new Toolset("3.5", engine.BinPath));
            engine.AddToolset(new Toolset("2.0", "anotherToolsPath"));

            string solutionFileContents =
                @"
                Microsoft Visual Studio Solution File, Format Version 9.00
                # Visual Studio 2005
                Global
                    GlobalSection(SolutionConfigurationPlatforms) = preSolution
                        Debug|AnyCPU = Debug|AnyCPU
                        Release|AnyCPU = Release|AnyCPU
                    EndGlobalSection
                    GlobalSection(SolutionProperties) = preSolution
                        HideSolutionNode = FALSE
                    EndGlobalSection
                EndGlobal
                ";

            string solutionFullPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("ConsoleApplication1.sln", solutionFileContents);

            // The parent project doesn't declare its ToolsVersion, and its ToolsVersion is not overridden
            string parentProjectContent = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
            Project parentProject =
                ObjectModelHelpers.CreateInMemoryProject(engine, parentProjectContent, null);

            EngineProxy engineProxy = CreateEngineProxyWithDummyTaskEngine(engine, parentProject);
            bool success = engineProxy.BuildProjectFile
                (solutionFullPath, null, null, null, "3.5");

            Assertion.Assert("Expected a successful build!", success);
        }
开发者ID:nikson,项目名称:msbuild,代码行数:42,代码来源:EngineProxy_Tests.cs

示例13: ToolsVersionTestHelper

        private ITaskItem ToolsVersionTestHelper(string parentProjectToolsVersionInProject,
                                                 string parentProjectToolsVersionOverride,
                                                 string toolsVersionPassedToEngineProxy)
        {
            Engine engine = new Engine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath));
            engine.AddToolset(new Toolset("44.0", "someToolsPath"));
            engine.AddToolset(new Toolset("55.0", "anotherToolsPath"));
            engine.AddToolset(new Toolset("66.0", "yetanotherToolsPath"));

            // The child project declares its ToolsVersion
            string childProjectFullPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("child.proj", @"
                      <Project ToolsVersion='44.0' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
                          <ItemGroup>
                              <ToolsVersionItem Include='$(MSBuildToolsVersion)'>
                                  <ToolsPath>$(MSBuildToolsPath)</ToolsPath>
                                  <BinPath>$(MSBuildBinPath)</BinPath>
                              </ToolsVersionItem>
                          </ItemGroup>
                          <Target Name='Build' Outputs='@(ToolsVersionItem)' />
                      </Project>
                      ");

            // The parent project doesn't declare its ToolsVersion, and its ToolsVersion is not overridden
            string parentProjectContent = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'";
            if (parentProjectToolsVersionInProject != null)
            {
                parentProjectContent += String.Format(" ToolsVersion=\"{0}\"", parentProjectToolsVersionInProject);
            }
            parentProjectContent += "/>";

            Project parentProject =
                ObjectModelHelpers.CreateInMemoryProject(engine, parentProjectContent, null);

            if (parentProjectToolsVersionOverride != null)
            {
                parentProject.ToolsVersion = parentProjectToolsVersionOverride;
            }

            Dictionary<string, ITaskItem[]> targetOutputs =
                new Dictionary<string, ITaskItem[]>(StringComparer.OrdinalIgnoreCase);

            EngineProxy engineProxy = CreateEngineProxyWithDummyTaskEngine(engine, parentProject);
            bool success = engineProxy.BuildProjectFile
                (childProjectFullPath, null, null, targetOutputs, toolsVersionPassedToEngineProxy);

            ITaskItem toolsVersionItem = targetOutputs["Build"][0];

            Assertion.Assert("Expected a successful build!", success);

            return toolsVersionItem;
        }
开发者ID:nikson,项目名称:msbuild,代码行数:51,代码来源:EngineProxy_Tests.cs


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