Project.Load Metodo

Definizione

Carica il contenuto del file di un progetto nell'oggetto Project.Loads the contents of a project file into the Project object.

Overload

Load(String, ProjectLoadSettings)

Legge il contenuto del progetto da un file XML del progetto su disco.Reads the contents of this project from a project XML file on disk.

Load(TextReader, ProjectLoadSettings)

Legge il contenuto di questo progetto da una stringa con contenuto XML.Reads the contents of this project from a string containing the XML contents.

Load(TextReader)

Carica il contenuto della classe TextReader specificata nell'oggetto Project.Loads the contents of the specified TextReader into the Project object.

Load(String)

Carica il contenuto del file di progetto specificato nell'oggetto Project.Loads the contents of the specified project file into the Project object.

Esempi

Nell'esempio seguente viene creato Project un oggetto e vengono BuildItemutilizzate BuildPropertyle BuildItemGroupclassi, BuildPropertyGroup , e per elencare tutti gli elementi e le proprietà del progetto.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)

Legge il contenuto del progetto da un file XML del progetto su disco.Reads 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

Parametri

projectFileName
String

Stringa che rappresenta il nome del file da caricare.A string representing the name of the file to load.

projectLoadSettings
ProjectLoadSettings

Valore ProjectLoadSettings che specifica le impostazioni per il progetto caricato.A ProjectLoadSettings value that specifies the settings for the project being loaded.

Load(TextReader, ProjectLoadSettings)

Legge il contenuto di questo progetto da una stringa con contenuto XML.Reads 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

Parametri

textReader
TextReader

Oggetto TextReader che contiene il contenuto del progetto.A TextReader object containing the project contents.

projectLoadSettings
ProjectLoadSettings

Valore ProjectLoadSettings che specifica le impostazioni per il progetto caricato.A ProjectLoadSettings value that specifies the settings for the project being loaded.

Load(TextReader)

Carica il contenuto della classe TextReader specificata nell'oggetto Project.Loads the contents of the specified TextReader into the Project object.

public:
 void Load(System::IO::TextReader ^ textReader);
public void Load (System.IO.TextReader textReader);
member this.Load : System.IO.TextReader -> unit

Parametri

textReader
TextReader

Classe TextReader da caricare.The TextReader to load.

Eccezioni

Il file usato da textReaderTextReader non è un file di progetto valido.The file used by the textReaderTextReader is not a valid project file.

Load(String)

Carica il contenuto del file di progetto specificato nell'oggetto Project.Loads the contents of the specified project file into the Project object.

public:
 void Load(System::String ^ projectFileName);
public void Load (string projectFileName);
member this.Load : string -> unit
Public Sub Load (projectFileName As String)

Parametri

projectFileName
String

file di progetto da caricare.The project file to load.

Eccezioni

Il file specificato da projectFileName non è un file di progetto valido.The file specified by projectFileName is not a valid project file.

Esempi

Nell'esempio seguente viene creato Project un oggetto e vengono BuildItemutilizzate BuildPropertyle BuildItemGroupclassi, BuildPropertyGroup , e per elencare tutti gli elementi e le proprietà del progetto.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

Si applica a