共用方式為


Engine.BuildProjectFile Method

Include Protected Members
Include Inherited Members

Loads the specified project file and builds the project.

MSBuild is now included in Visual Studio instead of the .NET Framework. You can use MSBuild 12.0 side-by-side with versions previously deployed with the .NET Framework.For more information, see What's New in MSBuild 12.0.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

Overload List

  Name Description
Public method BuildProjectFile(String) Loads the specified project file and builds the project.MSBuild is now included in Visual Studio instead of the .NET Framework. You can use MSBuild 12.0 side-by-side with versions previously deployed with the .NET Framework.For more information, see What's New in MSBuild 12.0.
Public method BuildProjectFile(String, String) Loads the specified project file and builds the specified target of the project.MSBuild is now included in Visual Studio instead of the .NET Framework. You can use MSBuild 12.0 side-by-side with versions previously deployed with the .NET Framework.For more information, see What's New in MSBuild 12.0.
Public method BuildProjectFile(String, array<String[]) Loads the specified project file and builds the specified targets of the project.MSBuild is now included in Visual Studio instead of the .NET Framework. You can use MSBuild 12.0 side-by-side with versions previously deployed with the .NET Framework.For more information, see What's New in MSBuild 12.0.
Public method BuildProjectFile(String, array<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.MSBuild is now included in Visual Studio instead of the .NET Framework. You can use MSBuild 12.0 side-by-side with versions previously deployed with the .NET Framework.For more information, see What's New in MSBuild 12.0.
Public method BuildProjectFile(String, array<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.MSBuild is now included in Visual Studio instead of the .NET Framework. You can use MSBuild 12.0 side-by-side with versions previously deployed with the .NET Framework.For more information, see What's New in MSBuild 12.0.
Public method BuildProjectFile(String, array<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.MSBuild is now included in Visual Studio instead of the .NET Framework. You can use MSBuild 12.0 side-by-side with versions previously deployed with the .NET Framework.For more information, see What's New in MSBuild 12.0.
Public method BuildProjectFile(String, array<String[], BuildPropertyGroup, IDictionary, BuildSettings, String) Loads a project file from disk and builds the given targets.MSBuild is now included in Visual Studio instead of the .NET Framework. You can use MSBuild 12.0 side-by-side with versions previously deployed with the .NET Framework.For more information, see What's New in MSBuild 12.0.

Top

Examples

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.

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
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");

        }
    }
}

See Also

Reference

Engine Class

Microsoft.Build.BuildEngine Namespace