This repository has been archived by the owner on Mar 20, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 DotNetOpenId.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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters