-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathProgram.cs
More file actions
89 lines (76 loc) · 2.95 KB
/
Copy pathProgram.cs
File metadata and controls
89 lines (76 loc) · 2.95 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace MonoBuildScriptGenerator
{
class Program
{
private static XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003";
static IEnumerable<string> GetIncludes(IEnumerable<XElement> itemGroups, string name)
{
return itemGroups
.SelectMany(x => x.Elements(ns + name).Attributes("Include"))
.Where(x => x != null)
.Select(x => x.Value);
}
static IEnumerable<XElement> GetItemGroups(XDocument document)
{
return document.Root.Elements(ns + "ItemGroup");
}
static Project LoadProject(string csproj)
{
var path = Path.GetDirectoryName(csproj);
var doc = XDocument.Load(csproj);
var itemGroups = GetItemGroups(doc);
return new Project(
csproj,
GetIncludes(itemGroups, "Reference"),
GetIncludes(itemGroups, "Compile")
.Select(x => Path.IsPathRooted(x) ? x : Path.Combine(path, x)),
null,
null,
GetIncludes(itemGroups, "None"));
}
static string CreateRefArg(Project project)
{
return string.Join(" ", project.Reference.Select(x => "-r:" + x));
}
static string CreateCompileArgs(Project project)
{
return string.Join(" ", project.Compile.Select(x => "\"" + x + "\""));
}
static void Main(string[] args)
{
var projects = args[0]
.Split(',')
.Select(LoadProject)
.ToArray();
var outFile = args[1];
var script = args[2];
var mainProject = projects.First();
var asmInfo = @"\assemblyinfo.cs";
var assemblyInfo = mainProject.Compile
.FirstOrDefault(x => x.ToLower().EndsWith(asmInfo));
var mergedReference = projects.SelectMany(x => x.Reference).Distinct();
var mergedCompile = projects
.SelectMany(x => x.Compile)
.Where(x => !x.ToLower().EndsWith(asmInfo) || x == assemblyInfo)
.Distinct();
var mergedCopies = projects.SelectMany(x => x.Copies).Distinct();
var mergedProject = new Project(
mainProject.CSProj,
mergedReference,
mergedCompile,
outFile,
new [] { "MONO", "DEBUG", "TRACE" },
mergedCopies);
var generator = new WindowsBuildScriptGenerator();
var cmd = generator.CreateScript(mergedProject);
File.WriteAllText(script, cmd);
}
}
}