This topic has not yet been rated - Rate this topic

Engine Class

Note: This API is now obsolete.

Represents the MSBuild engine.

System.Object
  Microsoft.Build.BuildEngine.Engine

Namespace:  Microsoft.Build.BuildEngine
Assembly:  Microsoft.Build.Engine (in Microsoft.Build.Engine.dll)
[ObsoleteAttribute("This class has been deprecated. Please use Microsoft.Build.Evaluation.ProjectCollection from the Microsoft.Build assembly instead.")]
public class Engine

The Engine type exposes the following members.

  Name Description
Public method Engine() Initializes a new instance of the Engine class.
Public method Engine(BuildPropertyGroup) Initializes a new instance of the Engine class.
Public method Engine(String) Obsolete. Initializes a new instance of the Engine class that has the specified BinPath.
Public method Engine(ToolsetDefinitionLocations) Initializes a new instance of the Engine class.
Public method Engine(BuildPropertyGroup, ToolsetDefinitionLocations) Initializes a new instance of the Engine class.
Public method Engine(BuildPropertyGroup, ToolsetDefinitionLocations, Int32, String) Initializes a new instance of the Engine class.
Top
  Name Description
Public property BinPath Obsolete. Gets or sets the path to MSBuild.exe.
Public property BuildEnabled Gets or sets a value that indicates whether the building of targets in the project is enabled.
Public property DefaultToolsVersion The default ToolsVersion of this build engine.
Public property Static member GlobalEngine Gets the Engine that is global (shared) for this AppDomain.
Public property GlobalProperties Gets or sets a collection of the global properties for the project.
Public property IsBuilding Gets whether a project is currently being built.
Public property OnlyLogCriticalEvents Gets or sets a value that indicates whether to only log critical events, such as warnings and errors, during the build.
Public property Toolsets Returns the collection of Toolsets that are recognized by this build engine instance.
Public property Static member Version Gets the version of the Engine.
Top
  Name Description
Public method BuildProject(Project) Builds the specified Project.
Public method BuildProject(Project, String) Builds the specified target of the specified Project.
Public method BuildProject(Project, String[]) Builds the specified targets of the specified Project.
Public method BuildProject(Project, String[], IDictionary) Builds the specified targets of the specified Project, and returns the outputs of the targets.
Public method BuildProject(Project, String[], IDictionary, BuildSettings) Builds the specified targets of the specified Project with the specified BuildSettings, and returns the outputs of the targets.
Public method BuildProjectFile(String) Loads the specified project file and builds the project.
Public method BuildProjectFile(String, String) Loads the specified project file and builds the specified target of the project.
Public method BuildProjectFile(String, String[]) Loads the specified project file and builds the specified targets of the project.
Public method BuildProjectFile(String, String[], BuildPropertyGroup) Loads the specified project file and builds the specified targets of the project with the specified GlobalProperties, and returns the outputs of the targets.
Public method BuildProjectFile(String, String[], BuildPropertyGroup, IDictionary) Loads the specified project file and builds the specified targets of the project with the specified GlobalProperties, and returns the outputs of the targets.
Public method BuildProjectFile(String, String[], BuildPropertyGroup, IDictionary, BuildSettings) 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.
Public method BuildProjectFile(String, String[], BuildPropertyGroup, IDictionary, BuildSettings, String) Loads a project file from disk and builds the given targets.
Public method BuildProjectFiles Loads a set of project files from disk and then builds the given list of targets for each project.
Public method CreateNewProject Creates an empty Project object that is associated with this Engine.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetLoadedProject Returns the Project object that is associated with the specified project file.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method RegisterDistributedLogger Registers distributed loggers with the build engine.
Public method RegisterLogger Registers the specified logger with the Engine.
Public method Shutdown Called when the host is finished with this build engine. It unregisters loggers and shuts down nodes.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method UnloadAllProjects Removes all references to Project objects from the Engine.
Public method UnloadProject Removes the reference to the specified Project from the Engine.
Public method UnregisterAllLoggers Unregisters all loggers from the Engine.
Top

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.

The following example creates an Engine object and uses the BuildProjectFile method to build a project file. 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");

        }
    }
}


.NET Framework

Supported in: 3.5, 3.0, 2.0
Obsolete (compiler warning) in 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
how to compile the C# project using 3.5 Engine class?
Visual Studio 2008 and .net 3.5 framework is used to build above mention code.

If I compile  *.vcproj in the below mention function.
engine.BuildProjectFile(@"c:\temp\validate.vcproj");
 It works perfectly fine. Code is compiled and binary is generated.


While If I set path of  *.csproj project in the below metion function.
engine.BuildProjectFile(@"c:\temp\validate.csproj");
It generates the error.

So help us to compile the C# project using 3.5 .net framework engine classes ?