共用方式為


Engine.BuildProjectFile Method

Definition

Loads the specified project file and builds the project.

Overloads

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

Loads a project file from disk, and builds the specified list of targets. This overload takes a set of global properties to use for the build, returns the target outputs, and also allows the caller to specify additional build flags.

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

Loads a project file from disk, and builds the specified list of targets. This overload takes a set of global properties to use for the build, returns the target outputs, and also allows the caller to specify additional build flags.

BuildProjectFile(String, String[], BuildPropertyGroup)

Loads a project file from disk, and builds the specified list of targets. This overload takes a set of global properties to use for the build.

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

Loads a project file from disk, and builds the specified list of targets. This overload takes a set of global properties to use for the build and returns the target outputs.

BuildProjectFile(String, String)

Loads a project file from disk, and builds the specified target.

BuildProjectFile(String)

Loads a project file from disk, and builds the default targets.

BuildProjectFile(String, String[])

Loads a project file from disk, and builds the specified list of targets.

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.

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

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

Source:
Engine.cs

Loads a project file from disk, and builds the specified list of targets. This overload takes a set of global properties to use for the build, returns the target outputs, and also allows the caller to specify additional build flags.

public:
 bool BuildProjectFile(System::String ^ projectFile, cli::array <System::String ^> ^ targetNames, Microsoft::Build::BuildEngine::BuildPropertyGroup ^ globalProperties, System::Collections::IDictionary ^ targetOutputs, Microsoft::Build::BuildEngine::BuildSettings buildFlags, System::String ^ toolsVersion);
public bool BuildProjectFile (string projectFile, string[] targetNames, Microsoft.Build.BuildEngine.BuildPropertyGroup globalProperties, System.Collections.IDictionary targetOutputs, Microsoft.Build.BuildEngine.BuildSettings buildFlags, string toolsVersion);
member this.BuildProjectFile : string * string[] * Microsoft.Build.BuildEngine.BuildPropertyGroup * System.Collections.IDictionary * Microsoft.Build.BuildEngine.BuildSettings * string -> bool
Public Function BuildProjectFile (projectFile As String, targetNames As String(), globalProperties As BuildPropertyGroup, targetOutputs As IDictionary, buildFlags As BuildSettings, toolsVersion As String) As Boolean

Parameters

projectFile
String
targetNames
String[]

Can be null, if caller wants to build the default targets for the project.

globalProperties
BuildPropertyGroup

Can be null if no global properties are needed.

targetOutputs
IDictionary

Can be null if outputs are not needed.

buildFlags
BuildSettings

Specifies additional options to alter the behavior of the build.

toolsVersion
String

Tools version to impose on the project in this build

Returns

true, if build succeeds

Remarks

If this project file is already in our list of in-progress projects, we use the existing Project object instead of instantiating a new one. Always use this method to build projects within projects, otherwise the build won't be optimized.

Applies to

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

Source:
Engine.cs

Loads a project file from disk, and builds the specified list of targets. This overload takes a set of global properties to use for the build, returns the target outputs, and also allows the caller to specify additional build flags.

public:
 bool BuildProjectFile(System::String ^ projectFile, cli::array <System::String ^> ^ targetNames, Microsoft::Build::BuildEngine::BuildPropertyGroup ^ globalProperties, System::Collections::IDictionary ^ targetOutputs, Microsoft::Build::BuildEngine::BuildSettings buildFlags);
public bool BuildProjectFile (string projectFile, string[] targetNames, Microsoft.Build.BuildEngine.BuildPropertyGroup globalProperties, System.Collections.IDictionary targetOutputs, Microsoft.Build.BuildEngine.BuildSettings buildFlags);
member this.BuildProjectFile : string * string[] * Microsoft.Build.BuildEngine.BuildPropertyGroup * System.Collections.IDictionary * Microsoft.Build.BuildEngine.BuildSettings -> bool
Public Function BuildProjectFile (projectFile As String, targetNames As String(), globalProperties As BuildPropertyGroup, targetOutputs As IDictionary, buildFlags As BuildSettings) As Boolean

Parameters

projectFile
String
targetNames
String[]

Can be null, if caller wants to build the default targets for the project.

globalProperties
BuildPropertyGroup

Can be null if no global properties are needed.

targetOutputs
IDictionary

Can be null if outputs are not needed.

buildFlags
BuildSettings

Specifies additional options to alter the behavior of the build.

Returns

true, if build succeeds

Remarks

If this project file is already in our list of in-progress projects, we use the existing Project object instead of instantiating a new one. Always use this method to build projects within projects, otherwise the build won't be optimized.

Applies to

BuildProjectFile(String, String[], BuildPropertyGroup)

Source:
Engine.cs

Loads a project file from disk, and builds the specified list of targets. This overload takes a set of global properties to use for the build.

public:
 bool BuildProjectFile(System::String ^ projectFile, cli::array <System::String ^> ^ targetNames, Microsoft::Build::BuildEngine::BuildPropertyGroup ^ globalProperties);
public bool BuildProjectFile (string projectFile, string[] targetNames, Microsoft.Build.BuildEngine.BuildPropertyGroup globalProperties);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public bool BuildProjectFile (string projectFile, string[] targetNames, Microsoft.Build.BuildEngine.BuildPropertyGroup globalProperties);
member this.BuildProjectFile : string * string[] * Microsoft.Build.BuildEngine.BuildPropertyGroup -> bool
[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]
member this.BuildProjectFile : string * string[] * Microsoft.Build.BuildEngine.BuildPropertyGroup -> bool
Public Function BuildProjectFile (projectFile As String, targetNames As String(), globalProperties As BuildPropertyGroup) As Boolean

Parameters

projectFile
String
targetNames
String[]

Can be null, if caller wants to build the default targets for the project.

globalProperties
BuildPropertyGroup

Can be null if no global properties are needed.

Returns

true, if build succeeds

Attributes

Applies to

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

Source:
Engine.cs

Loads a project file from disk, and builds the specified list of targets. This overload takes a set of global properties to use for the build and returns the target outputs.

public:
 bool BuildProjectFile(System::String ^ projectFile, cli::array <System::String ^> ^ targetNames, Microsoft::Build::BuildEngine::BuildPropertyGroup ^ globalProperties, System::Collections::IDictionary ^ targetOutputs);
public bool BuildProjectFile (string projectFile, string[] targetNames, Microsoft.Build.BuildEngine.BuildPropertyGroup globalProperties, System.Collections.IDictionary targetOutputs);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public bool BuildProjectFile (string projectFile, string[] targetNames, Microsoft.Build.BuildEngine.BuildPropertyGroup globalProperties, System.Collections.IDictionary targetOutputs);
member this.BuildProjectFile : string * string[] * Microsoft.Build.BuildEngine.BuildPropertyGroup * System.Collections.IDictionary -> bool
[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]
member this.BuildProjectFile : string * string[] * Microsoft.Build.BuildEngine.BuildPropertyGroup * System.Collections.IDictionary -> bool
Public Function BuildProjectFile (projectFile As String, targetNames As String(), globalProperties As BuildPropertyGroup, targetOutputs As IDictionary) As Boolean

Parameters

projectFile
String
targetNames
String[]

Can be null, if caller wants to build the default targets for the project.

globalProperties
BuildPropertyGroup

Can be null if no global properties are needed.

targetOutputs
IDictionary

Can be null if outputs are not needed.

Returns

true, if build succeeds

Attributes

Applies to

BuildProjectFile(String, String)

Source:
Engine.cs

Loads a project file from disk, and builds the specified target.

public:
 bool BuildProjectFile(System::String ^ projectFile, System::String ^ targetName);
public bool BuildProjectFile (string projectFile, string targetName);
member this.BuildProjectFile : string * string -> bool
Public Function BuildProjectFile (projectFile As String, targetName As String) As Boolean

Parameters

projectFile
String
targetName
String

Can be null, if caller wants to build the default targets for the project.

Returns

true, if build succeeds

Applies to

BuildProjectFile(String)

Source:
Engine.cs

Loads a project file from disk, and builds the default targets.

public:
 bool BuildProjectFile(System::String ^ projectFile);
public bool BuildProjectFile (string projectFile);
member this.BuildProjectFile : string -> bool
Public Function BuildProjectFile (projectFile As String) As Boolean

Parameters

projectFile
String

Returns

true, if build succeeds

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.

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

Applies to

BuildProjectFile(String, String[])

Source:
Engine.cs

Loads a project file from disk, and builds the specified list of targets.

public:
 bool BuildProjectFile(System::String ^ projectFile, cli::array <System::String ^> ^ targetNames);
public bool BuildProjectFile (string projectFile, string[] targetNames);
member this.BuildProjectFile : string * string[] -> bool
Public Function BuildProjectFile (projectFile As String, targetNames As String()) As Boolean

Parameters

projectFile
String
targetNames
String[]

Can be null, if caller wants to build the default targets for the project.

Returns

true, if build succeeds

Applies to