This repository has been archived by the owner on Aug 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
MSBuild.cs
78 lines (64 loc) · 2.05 KB
/
MSBuild.cs
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
#region License
// Copyright Jeremy Skinner (http://www.jeremyskinner.co.uk) and Contributors
//
// Licensed under the Microsoft Public License. You may
// obtain a copy of the license at:
//
// http://www.microsoft.com/opensource/licenses.mspx
//
// By using this source code in any fashion, you are agreeing
// to be bound by the terms of the Microsoft Public License.
//
// You must not remove this notice, or any other, from this software.
#endregion
namespace Phantom.Core.Builtins {
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
/// <summary>
/// Provides MSBuild integration
/// </summary>
public class msbuild : ExecutableTool<msbuild> {
public msbuild() {
toolPath = BuildMsbuildPath("4.0");
configuration = "debug";
verbosity = "minimal";
targets = new[] {"build"};
properties = new Dictionary<string, object>();
}
private string BuildMsbuildPath(string version) {
if(version == "4.0" || version == "4") {
version = "4.0.30319";
}
string windir = Environment.GetEnvironmentVariable("windir");
if (windir != null) {
return Path.Combine(windir, "Microsoft.NET/Framework/v" + version + "/msbuild.exe");
}
return "/usr/bin/xbuild";
}
public string configuration { get; set; }
public string[] targets { get; set; }
public string verbosity { get; set; }
public IDictionary properties { get; set; }
public string file { get; set; }
string _version;
public string version {
get { return _version; }
set {
_version = value;
toolPath = BuildMsbuildPath(value);
}
}
protected override void Execute() {
if (string.IsNullOrEmpty(file)) {
throw new InvalidOperationException("Please specify the 'file' property for calls to msbuild.");
}
string args = "\"" + file + "\" /p:Configuration=" + configuration + " /t:" + string.Join(";", targets) + " /v:" + verbosity;
foreach (DictionaryEntry entry in properties) {
args += " /p:" + entry.Key + "=" + entry.Value.ToString().Replace(" ", "%20");
}
Execute(args);
}
}
}