0

I need get a list "Imports" of project in Addin VS 2008 - .NET 3.5.

In VS2010 - .NET 4.0, I use:

EnvDTE.Project project = GetProject();
var project1 = new Microsoft.Build.Evaluation.Project(project.FullName);
project1.Xml.Imports.ForEach(i => {
                    Trace.WriteLine("\t Import Project: " + i.Project); 
});

but fails in VS2008 (Microsoft.Build assembly not found).

Any suggestions?

Kiquenet
  • 14,494
  • 35
  • 148
  • 243

1 Answers1

0

Using VS2008 and .net 3.5, Microsoft.Build.BuildEngine.Engine is obsolete in .net 4.0

    var engine = new Microsoft.Build.BuildEngine.Engine();
    var proj = new Microsoft.Build.BuildEngine.Project(engine);
    proj.Load(project.FullName);
    foreach (Microsoft.Build.BuildEngine.Import import in proj.Imports)
    {
        contieneTargets = import.ProjectPath.ContainsWithStringComparison("Microsoft.VisualStudio.SharePoint.targets", StringComparison.InvariantCultureIgnoreCase);
        Trace.WriteLine("\t Import Project: " + import.ProjectPath);
        if (contieneTargets) break;
    }

Only a problem: when this code is executed several times, I get some error that the project yet loaded.

System.InvalidOperationException: An equivalent project (a project with the same global properties and tools version) is already present in the project collection, with the path "test.csproj". To load an equivalent into this project collection, unload this project first.

Kiquenet
  • 14,494
  • 35
  • 148
  • 243