共用方式為


Project.Load Method

Include Protected Members
Include Inherited Members

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

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 Load(TextReader) Loads the contents of the specified TextReader into the Project object.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 Load(String) Loads the contents of the specified project file into the Project object.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 Load(TextReader, ProjectLoadSettings) Reads the contents of this project from a string containing the XML contents.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 Load(String, ProjectLoadSettings) Reads the contents of this project from a project XML file on disk.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 a Project object and uses the BuildItem, BuildProperty, BuildItemGroup, and BuildPropertyGroup classes to list all the items and properties in the project.

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
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 teh 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);
                }
            }            
        }
    }
}

See Also

Reference

Project Class

Microsoft.Build.BuildEngine Namespace