forked from DotNetOpenAuth/DotNetOpenAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChangeAssemblyReference.cs
More file actions
47 lines (41 loc) · 1.25 KB
/
ChangeAssemblyReference.cs
File metadata and controls
47 lines (41 loc) · 1.25 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
using System;
using System.Linq;
using System.IO;
using System.Xml;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.Build.BuildEngine;
namespace DotNetOpenAuth.BuildTasks {
/// <summary>
/// Replaces Reference items HintPaths in a set of projects.
/// </summary>
public class ChangeAssemblyReference : Task {
/// <summary>
/// The projects to alter.
/// </summary>
[Required]
public ITaskItem[] Projects { get; set; }
/// <summary>
/// The project reference to remove.
/// </summary>
[Required]
public string OldReference { get; set; }
/// <summary>
/// The assembly reference to add.
/// </summary>
[Required]
public string NewReference { get; set; }
const string msbuildNamespace = "http://schemas.microsoft.com/developer/msbuild/2003";
public override bool Execute() {
foreach (var project in Projects) {
Project doc = new Project();
doc.Load(project.ItemSpec);
var reference = doc.GetEvaluatedItemsByName("Reference").OfType<BuildItem>().
Where(item => string.Equals(item.GetMetadata("HintPath"), OldReference, StringComparison.OrdinalIgnoreCase)).Single();
reference.SetMetadata("HintPath", NewReference);
doc.Save(project.ItemSpec);
}
return true;
}
}
}