Engine.BinPath Property
Note: This API is now obsolete.
Gets or sets the path to MSBuild.exe.
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.
Namespace: Microsoft.Build.BuildEngine
Assembly: Microsoft.Build.Engine (in Microsoft.Build.Engine.dll)
Syntax
'Declaration
<ObsoleteAttribute("Avoid setting BinPath. If you were simply passing in the .NET Framework location as the BinPath, no other action is necessary. Otherwise, define Toolsets instead in the registry or config file, or by adding elements to the Engine's ToolsetCollection, in order to use a custom BinPath.")> _
Public Property BinPath As String
[ObsoleteAttribute("Avoid setting BinPath. If you were simply passing in the .NET Framework location as the BinPath, no other action is necessary. Otherwise, define Toolsets instead in the registry or config file, or by adding elements to the Engine's ToolsetCollection, in order to use a custom BinPath.")]
public string BinPath { get; set; }
[ObsoleteAttribute(L"Avoid setting BinPath. If you were simply passing in the .NET Framework location as the BinPath, no other action is necessary. Otherwise, define Toolsets instead in the registry or config file, or by adding elements to the Engine's ToolsetCollection, in order to use a custom BinPath.")]
public:
property String^ BinPath {
String^ get ();
void set (String^ value);
}
[<ObsoleteAttribute("Avoid setting BinPath. If you were simply passing in the .NET Framework location as the BinPath, no other action is necessary. Otherwise, define Toolsets instead in the registry or config file, or by adding elements to the Engine's ToolsetCollection, in order to use a custom BinPath.")>]
member BinPath : string with get, set
function get BinPath () : String
function set BinPath (value : String)
Property Value
Type: System.String
The path to MSBuild.exe.
Remarks
In MSBuild 3.5, the "BinPath" is superseded by the "ToolsPath." Therefore, in the .Targets file, use MSBuildToolsPath rather than MBBuildBinPath. In the MSBuild object model, "BinPath" relates to the Toolset you are running. The steps to get the path from the build engine are as follows:
Get the default tools version.
Get the Toolset map.
Find the Toolset, based on the string in the map.
Get the Toolset.
Get the path from the Toolset.
This procedure is not required if you are creating the engine. In that case, you already know the Toolset path.
Because projects in a solution can use different Toolsets, you can also obtain the MSBuild.exe path from the project, as follows.
project.EvaluatedProperties[ReservedPropertyNames.toolsPath].FinalValue
For more information about Toolsets, see MSBuild Tool Set (ToolsVersion).
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");
}
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see dd66cd4c-b087-415f-9c3e-94e3a1835f74.