Compartir a través de


Project.Load Method

Definition

Loads the contents of a project file into the Project object.

Overloads

Load(String, ProjectLoadSettings)

Reads in the contents of this project from a project XML file on disk.

Load(TextReader, ProjectLoadSettings)

Reads in the contents of this project from a string containing the Xml contents.

Load(TextReader)

Reads in the contents of this project from a string containing the Xml contents.

Load(String)

Reads in the contents of this project from a project XML file on disk.

Examples

The following example creates a Project object and uses the BuildItem, BuildProperty, BuildItemGroup, and BuildPropertyGroup classes to list all the items and properties in the project.

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

namespace ListItemAndPropertiesCS
{
    class Program
    {
        static void Main(string[] args)
        {
            // SET THIS TO POINT TO THE RIGHT LOCATION
            Engine.GlobalEngine.BinPath = @"C:\Windows\Microsoft.NET\Framework\v2.0.xxxxx";

            // Create a new empty project
            Project project = new Project();

            // Load a project
            project.Load(@"c:\temp\validate.proj");

            Console.WriteLine("Project Properties");
            Console.WriteLine("----------------------------------");

            // Iterate through the various property groups and subsequently
            // through the various properties
            foreach (BuildPropertyGroup propertyGroup in project.PropertyGroups)
            {
                foreach (BuildProperty prop in propertyGroup)
                {
                    Console.WriteLine("{0}:{1}", prop.Name, prop.Value);
                }
            }

            Console.WriteLine();
            Console.WriteLine("Project Items");
            Console.WriteLine("----------------------------------");

            // Iterate through the various itemgroups
            // and subsequently through the items
            foreach (BuildItemGroup itemGroup in project.ItemGroups)
            {
                foreach (BuildItem item in itemGroup)
                {
                    Console.WriteLine("{0}:{1}", item.Name, item.Include);
                }
            }
        }
    }
}
Module Module1
    'You need to add references to Microsoft.Build.BuildEngine and
    'Microsoft.Build.Framework
    Sub Main()
        'Set this to point to the location where the 2.0 clr/tools are installed
        Engine.GlobalEngine.BinPath = "C:\windows\microsoft.net\framework\v2.0.xxxxx"

        'Create a new empty project
        Dim project As New Project()

        'Load a project
        project.Load("c:\temp\validate.proj")

        'Output a header
        Console.WriteLine("Project Properties")
        Console.WriteLine("----------------------------------")

        'Iterate through the various property groups and subsequently
        'through the various properties
        For Each propertyGroup As BuildPropertyGroup In project.PropertyGroups
            For Each prop As BuildProperty In propertyGroup
                Console.WriteLine("{0}:{1}", prop.Name, prop.Value)
            Next
        Next

        Console.WriteLine()
        Console.WriteLine("Project Items")
        Console.WriteLine("----------------------------------")

        'Iterate through the various itemgroups
        'and subsequently through the items
        For Each itemGroup As BuildItemGroup In project.ItemGroups
            For Each item As BuildItem In itemGroup
                Console.WriteLine("{0}:{1}", item.Name, item.Include)
            Next
        Next
    End Sub

End Module

Load(String, ProjectLoadSettings)

Source:
Project.cs

Reads in the contents of this project from a project XML file on disk.

public:
 void Load(System::String ^ projectFileName, Microsoft::Build::BuildEngine::ProjectLoadSettings projectLoadSettings);
public void Load (string projectFileName, Microsoft.Build.BuildEngine.ProjectLoadSettings projectLoadSettings);
member this.Load : string * Microsoft.Build.BuildEngine.ProjectLoadSettings -> unit
Public Sub Load (projectFileName As String, projectLoadSettings As ProjectLoadSettings)

Parameters

projectFileName
String

A string representing the name of the file to load.

projectLoadSettings
ProjectLoadSettings

A ProjectLoadSettings value that specifies the settings for the project being loaded.

Exceptions

Applies to

Load(TextReader, ProjectLoadSettings)

Source:
Project.cs

Reads in the contents of this project from a string containing the Xml contents.

public:
 void Load(System::IO::TextReader ^ textReader, Microsoft::Build::BuildEngine::ProjectLoadSettings projectLoadSettings);
public void Load (System.IO.TextReader textReader, Microsoft.Build.BuildEngine.ProjectLoadSettings projectLoadSettings);
member this.Load : System.IO.TextReader * Microsoft.Build.BuildEngine.ProjectLoadSettings -> unit
Public Sub Load (textReader As TextReader, projectLoadSettings As ProjectLoadSettings)

Parameters

textReader
TextReader

A TextReader object containing the project contents.

projectLoadSettings
ProjectLoadSettings

A ProjectLoadSettings value that specifies the settings for the project being loaded.

Exceptions

Applies to

Load(TextReader)

Source:
Project.cs

Reads in the contents of this project from a string containing the Xml contents.

public:
 void Load(System::IO::TextReader ^ textReader);
public void Load (System.IO.TextReader textReader);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public void Load (System.IO.TextReader textReader);
member this.Load : System.IO.TextReader -> unit
[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]
member this.Load : System.IO.TextReader -> unit
Public Sub Load (textReader As TextReader)

Parameters

textReader
TextReader

The TextReader to load.

Attributes

Exceptions

Applies to

Load(String)

Source:
Project.cs

Reads in the contents of this project from a project XML file on disk.

public:
 void Load(System::String ^ projectFileName);
public void Load (string projectFileName);
[System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public void Load (string projectFileName);
member this.Load : string -> unit
[<System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]
member this.Load : string -> unit
Public Sub Load (projectFileName As String)

Parameters

projectFileName
String

The project file to load.

Attributes

Exceptions

Examples

The following example creates a Project object and uses the BuildItem, BuildProperty, BuildItemGroup, and BuildPropertyGroup classes to list all the items and properties in the project.

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

namespace ListItemAndPropertiesCS
{
    class Program
    {
        static void Main(string[] args)
        {
            // SET THIS TO POINT TO THE RIGHT LOCATION
            Engine.GlobalEngine.BinPath = @"C:\Windows\Microsoft.NET\Framework\v2.0.xxxxx";

            // Create a new empty project
            Project project = new Project();

            // Load a project
            project.Load(@"c:\temp\validate.proj");

            Console.WriteLine("Project Properties");
            Console.WriteLine("----------------------------------");

            // Iterate through the various property groups and subsequently
            // through the various properties
            foreach (BuildPropertyGroup propertyGroup in project.PropertyGroups)
            {
                foreach (BuildProperty prop in propertyGroup)
                {
                    Console.WriteLine("{0}:{1}", prop.Name, prop.Value);
                }
            }

            Console.WriteLine();
            Console.WriteLine("Project Items");
            Console.WriteLine("----------------------------------");

            // Iterate through the various itemgroups
            // and subsequently through the items
            foreach (BuildItemGroup itemGroup in project.ItemGroups)
            {
                foreach (BuildItem item in itemGroup)
                {
                    Console.WriteLine("{0}:{1}", item.Name, item.Include);
                }
            }
        }
    }
}
Module Module1
    'You need to add references to Microsoft.Build.BuildEngine and
    'Microsoft.Build.Framework
    Sub Main()
        'Set this to point to the location where the 2.0 clr/tools are installed
        Engine.GlobalEngine.BinPath = "C:\windows\microsoft.net\framework\v2.0.xxxxx"

        'Create a new empty project
        Dim project As New Project()

        'Load a project
        project.Load("c:\temp\validate.proj")

        'Output a header
        Console.WriteLine("Project Properties")
        Console.WriteLine("----------------------------------")

        'Iterate through the various property groups and subsequently
        'through the various properties
        For Each propertyGroup As BuildPropertyGroup In project.PropertyGroups
            For Each prop As BuildProperty In propertyGroup
                Console.WriteLine("{0}:{1}", prop.Name, prop.Value)
            Next
        Next

        Console.WriteLine()
        Console.WriteLine("Project Items")
        Console.WriteLine("----------------------------------")

        'Iterate through the various itemgroups
        'and subsequently through the items
        For Each itemGroup As BuildItemGroup In project.ItemGroups
            For Each item As BuildItem In itemGroup
                Console.WriteLine("{0}:{1}", item.Name, item.Include)
            Next
        Next
    End Sub

End Module

Applies to