2010-05-05 12 views

cevap

3

:

using Microsoft.Build.Evaluation; 
using Microsoft.Build.Utilities; 

namespace MSBuildTasks 
{ 
    public class GetAllProperties : Task 
    { 
    public override bool Execute() 
    { 
     Project project = new Project(BuildEngine.ProjectFileOfTaskNode); 
     foreach (ProjectProperty evaluatedProperty in project.AllEvaluatedProperties) 
     { 
     if (!evaluatedProperty.IsEnvironmentProperty && 
      !evaluatedProperty.IsGlobalProperty && 
      !evaluatedProperty.IsReservedProperty) 
     { 
      string name = evaluatedProperty.Name; 
      string value = evaluatedProperty.EvaluatedValue; 
     } 

     // Do your stuff 
     } 

     return true; 
    } 
    } 
} 
6

önceki örnek dosyayı proje kilitlenir. Bu sorunlara neden olabilir. Örneğin, görevi aynı proje dosyasında birkaç kez çağırırsanız. İşte geliştirilmiş kod:

using System.Xml; 
using Microsoft.Build.Evaluation; 
using Microsoft.Build.Utilities; 

namespace MSBuildTasks 
{ 
    public class GetAllProperties : Task 
    { 
    public override bool Execute() 
    { 
     using (XmlReader projectFileReader = XmlReader.Create(BuildEngine.ProjectFileOfTaskNode)) 
     { 
     Project project = new Project(projectFileReader); 

     foreach (ProjectProperty property in project.AllEvaluatedProperties) 
     { 
      if (property.IsEnvironmentProperty) continue; 
      if (property.IsGlobalProperty) continue; 
      if (property.IsReservedProperty) continue; 

      string propertyName = property.Name; 
      string propertyValue = property.EvaluatedValue; 

      // Do your stuff 
     } 

     return true; 
     } 
    } 
    } 
} 
İlgili konular