forked from mikefourie-zz/MSBuildExplorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSBuildHelper.cs
More file actions
67 lines (58 loc) · 2.62 KB
/
MSBuildHelper.cs
File metadata and controls
67 lines (58 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//---------------------------------------------------------------------------------------------------------------------------
// <copyright file="MSBuildHelper.cs">(c) Mike Fourie. All other rights reserved.</copyright>
//---------------------------------------------------------------------------------------------------------------------------
namespace MSBuildExplorer
{
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
using MSBuildExplorer.DataModel;
internal static class MSBuildHelper
{
internal static MSBuildFile GetFile(FileInfo file)
{
using (ProjectCollection loadedProjects = new ProjectCollection())
{
Project currentProject = loadedProjects.GetLoadedProjects(file.FullName).FirstOrDefault();
if (currentProject != null)
{
loadedProjects.UnloadProject(currentProject);
}
loadedProjects.LoadProject(file.FullName);
currentProject = loadedProjects.GetLoadedProjects(file.FullName).FirstOrDefault();
MSBuildFile m = new MSBuildFile(currentProject);
if (currentProject.Targets != null)
{
SortedDictionary<string, ProjectTargetInstance> sortedTargets = new SortedDictionary<string, ProjectTargetInstance>(currentProject.Targets);
foreach (var t in sortedTargets)
{
ProjectTargetInstance pti = t.Value;
m.Targets.Add(new MSBuildTarget(pti, currentProject, m));
}
}
foreach (var us in currentProject.Xml.UsingTasks)
{
m.Usings.Add(new MSBuildUsing(currentProject, us));
}
foreach (ResolvedImport import in currentProject.Imports)
{
m.Imports.Add(new MSBuildImport(import));
}
foreach (var property in currentProject.Properties)
{
m.Properties.Add(new MSBuildProperties(property));
}
if (currentProject.AllEvaluatedItems != null)
{
foreach (var item in currentProject.AllEvaluatedItems)
{
m.Items.Add(new MSBuildItems(item.ItemType, item.UnevaluatedInclude, item.EvaluatedInclude, item.IsImported));
}
}
return m;
}
}
}
}