Engine 类

定义

警告

此 API 现已过时。

表示 MSBuild 引擎。Represents the MSBuild engine.

public ref class Engine
[System.Obsolete("This class has been deprecated. Please use Microsoft.Build.Evaluation.ProjectCollection from the Microsoft.Build assembly instead.")]
public class Engine
type Engine = class
Public Class Engine
继承
Engine
属性

示例

下面的示例创建一个 Engine 对象,并使用 BuildProjectFile 方法来生成项目文件。The following example creates an Engine object and uses the BuildProjectFile method to build a project file. FileLogger 类用于将信息记录到文件中。The FileLogger class is used to log information to a file.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Build.BuildEngine;

namespace BuildAProjectCS
{
    class Program
    {       
        static void Main(string[] args)
        {
            // Instantiate a new Engine object
            Engine engine = new Engine();

            // Point to the path that contains the .NET Framework 2.0 CLR and tools
            engine.BinPath = @"c:\windows\microsoft.net\framework\v2.0.xxxxx";

            // Instantiate a new FileLogger to generate build log
            FileLogger logger = new FileLogger();

            // Set the logfile parameter to indicate the log destination
            logger.Parameters = @"logfile=C:\temp\build.log";

            // Register the logger with the engine
            engine.RegisterLogger(logger);

            // Build a project file
            bool success = engine.BuildProjectFile(@"c:\temp\validate.proj");

            //Unregister all loggers to close the log file
            engine.UnregisterAllLoggers();

            if (success)
                Console.WriteLine("Build succeeded.");
            else
                Console.WriteLine(@"Build failed. View C:\temp\build.log for details");
        }
    }
}
Module Module1
    'Add references to Microsoft.Build.Framework and
    'Microsoft.Build.BuildEngine
    Sub Main()
        'Create a new Engine object
        Dim engine As New Engine()

        'Point to the path that contains the .NET Framework 2.0 CLR and tools
        engine.BinPath = "c:\windows\microsoft.net\framework\v2.0.xxxxx"

        'Instantiate a new FileLogger to generate a build log
        Dim logger As New FileLogger()

        'Set logfile parameter to indicate the log destination
        logger.Parameters = "logfile=c:\temp\build.log"

        'Register the logger with the engine
        engine.RegisterLogger(logger)

        'Build the project file
        Dim success As Boolean = engine.BuildProjectFile("c:\temp\validate.proj")

        'Unregister all loggers to close the log file
        engine.UnregisterAllLoggers()

        If success Then
            Console.WriteLine("Build succeeded.")
        Else
            Console.WriteLine("Build failed. View C:\temp\build.log for details.")
        End If
    End Sub

End Module

注解

在项目到项目依赖项的系统中,Engine 维护生成项目,因此可以避免在给定生成中多次在同一项目中生成相同的目标。In a system of project-to-project dependencies, the Engine maintains the building projects, making it possible to avoid building the same target in the same project more than once in a given build.

构造函数

Engine()

初始化 Engine 类的新实例。Initializes a new instance of the Engine class.

Engine(BuildPropertyGroup)

初始化 Engine 类的新实例。Initializes a new instance of the Engine class.

Engine(BuildPropertyGroup, ToolsetDefinitionLocations)

初始化 Engine 类的新实例。Initializes a new instance of the Engine class.

Engine(BuildPropertyGroup, ToolsetDefinitionLocations, Int32, String)

初始化 Engine 类的新实例。Initializes a new instance of the Engine class.

Engine(String)

初始化具有指定 EngineBinPath 类的新实例。Initializes a new instance of the Engine class that has the specified BinPath.

Engine(ToolsetDefinitionLocations)

初始化 Engine 类的新实例。Initializes a new instance of the Engine class.

属性

BinPath

获取或设置 MSBuild.exe 的路径。Gets or sets the path to MSBuild.exe.

BuildEnabled

获取或设置一个值,该值指示是否允许在项目中生成目标。Gets or sets a value that indicates whether the building of targets in the project is enabled.

DefaultToolsVersion

此生成引擎的默认 ToolsVersion。The default ToolsVersion of this build engine.

GlobalEngine

获取此 Engine 的全局(共享)AppDomainGets the Engine that is global (shared) for this AppDomain.

GlobalProperties

获取或设置项目的全局属性的集合。Gets or sets a collection of the global properties for the project.

IsBuilding

获取一个值,该值指示当前是否正在生成项目。Gets whether a project is currently being built.

OnlyLogCriticalEvents

获取或设置一个值,该值指示在生成过程中是否只记录关键事件,例如警告和错误。Gets or sets a value that indicates whether to only log critical events, such as warnings and errors, during the build.

Toolsets

获取或设置此生成引擎实例识别的“工具集”的集合。Gets or sets the collection of Toolsets that are recognized by this build engine instance.

Version

获取 Engine 的版本。Gets the version of the Engine.

方法

BuildProject(Project)

生成指定的 ProjectBuilds the specified Project.

BuildProject(Project, String)

生成指定 Project 的指定目标。Builds the specified target of the specified Project.

BuildProject(Project, String[])

生成指定 Project 的指定目标。Builds the specified targets of the specified Project.

BuildProject(Project, String[], IDictionary)

生成指定 Project 的指定目标,并返回目标的输出。Builds the specified targets of the specified Project, and returns the outputs of the targets.

BuildProject(Project, String[], IDictionary, BuildSettings)

使用指定的 Project 生成指定 BuildSettings 的指定目标,并返回目标的输出。Builds the specified targets of the specified Project with the specified BuildSettings, and returns the outputs of the targets.

BuildProjectFile(String)

加载指定的项目文件并生成项目。Loads the specified project file and builds the project.

BuildProjectFile(String, String)

加载指定的项目文件并生成项目的指定目标。Loads the specified project file and builds the specified target of the project.

BuildProjectFile(String, String[])

加载指定的项目文件并生成项目的指定目标。Loads the specified project file and builds the specified targets of the project.

BuildProjectFile(String, String[], BuildPropertyGroup)

加载指定的项目文件,使用指定的 GlobalProperties 生成项目的指定目标,并返回目标的输出。Loads the specified project file and builds the specified targets of the project with the specified GlobalProperties, and returns the outputs of the targets.

BuildProjectFile(String, String[], BuildPropertyGroup, IDictionary)

加载指定的项目文件,使用指定的 GlobalProperties 生成项目的指定目标,并返回目标的输出。Loads the specified project file and builds the specified targets of the project with the specified GlobalProperties, and returns the outputs of the targets.

BuildProjectFile(String, String[], BuildPropertyGroup, IDictionary, BuildSettings)

加载指定的项目文件,使用指定的 BuildSettingsGlobalProperties 生成项目的指定目标,并返回目标的输出。Loads the specified project file and builds the specified targets of the project with the specified BuildSettings and GlobalProperties, and returns the outputs of the targets.

BuildProjectFile(String, String[], BuildPropertyGroup, IDictionary, BuildSettings, String)

从磁盘加载项目文件并生成给定目标。Loads a project file from disk and builds the given targets.

BuildProjectFiles(String[], String[][], BuildPropertyGroup[], IDictionary[], BuildSettings, String[])

从磁盘加载一组项目文件,然后生成每个项目的给定目标列表。Loads a set of project files from disk and then builds the given list of targets for each project.

CreateNewProject()

创建一个与此 Project 关联的空 Engine 对象。Creates an empty Project object that is associated with this Engine.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLoadedProject(String)

返回与指定的项目文件关联的 Project 对象。Returns the Project object that is associated with the specified project file.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
RegisterDistributedLogger(ILogger, LoggerDescription)

向生成引擎注册分布式记录器。Registers distributed loggers with the build engine.

RegisterLogger(ILogger)

Engine 中注册指定的记录器。Registers the specified logger with the Engine.

Shutdown()

当主机完成此生成引擎时调用。Called when the host is finished with this build engine. 它将注销记录器并关闭节点。It unregisters loggers and shuts down nodes.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)
UnloadAllProjects()

Project 中移除对 Engine 对象的所有引用。Removes all references to Project objects from the Engine.

UnloadProject(Project)

Project 中移除对指定 Engine 的引用。Removes the reference to the specified Project from the Engine.

UnregisterAllLoggers()

将所有记录器从 Engine 中注销。Unregisters all loggers from the Engine.

适用于