summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-07-21 19:11:45 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2010-07-21 19:11:45 -0700
commit9533f64c85a79b80fb51843d151fa2046dc62b9c (patch)
tree21a9d5e86e6d8e5c975e9701b1553745e82aeda3 /src
parent3c09e09a3c850f2a2b86b4f97b3fbf738c436e6a (diff)
downloadDotNetOpenAuth-9533f64c85a79b80fb51843d151fa2046dc62b9c.zip
DotNetOpenAuth-9533f64c85a79b80fb51843d151fa2046dc62b9c.tar.gz
DotNetOpenAuth-9533f64c85a79b80fb51843d151fa2046dc62b9c.tar.bz2
Downgrading VS2010 sample projects to VS2008 now happens by creating NEW project and solution files rather than wiping out the VS2010 ones.
So now VS2008 and VS2010 users have solutions and projects they can open immediately.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth.BuildTasks/DowngradeProjects.cs47
1 files changed, 44 insertions, 3 deletions
diff --git a/src/DotNetOpenAuth.BuildTasks/DowngradeProjects.cs b/src/DotNetOpenAuth.BuildTasks/DowngradeProjects.cs
index b545541..2188cd0 100644
--- a/src/DotNetOpenAuth.BuildTasks/DowngradeProjects.cs
+++ b/src/DotNetOpenAuth.BuildTasks/DowngradeProjects.cs
@@ -10,6 +10,7 @@ namespace DotNetOpenAuth.BuildTasks {
using System.IO;
using System.Linq;
using System.Text;
+ using System.Text.RegularExpressions;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
@@ -24,6 +25,9 @@ namespace DotNetOpenAuth.BuildTasks {
[Required]
public ITaskItem[] Projects { get; set; }
+ [Output]
+ public ITaskItem[] DowngradedProjects { get; set; }
+
/// <summary>
/// Gets or sets a value indicating whether ASP.NET MVC 2 projects are downgraded to MVC 1.0.
/// </summary>
@@ -33,11 +37,26 @@ namespace DotNetOpenAuth.BuildTasks {
/// Executes this instance.
/// </summary>
public override bool Execute() {
+ var newProjectToOldProjectMapping = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
+ var createdProjectFiles = new List<TaskItem>();
+
+ foreach (ITaskItem taskItem in this.Projects) {
+ switch (GetClassification(taskItem)) {
+ case ProjectClassification.VS2010Project:
+ case ProjectClassification.VS2010Solution:
+ string projectNameForVS2008 = Path.Combine(
+ Path.GetDirectoryName(taskItem.ItemSpec),
+ Path.GetFileNameWithoutExtension(taskItem.ItemSpec) + "-vs2008" + Path.GetExtension(taskItem.ItemSpec));
+ newProjectToOldProjectMapping[taskItem.ItemSpec] = projectNameForVS2008;
+ break;
+ }
+ }
+
foreach (ITaskItem taskItem in this.Projects) {
switch (GetClassification(taskItem)) {
case ProjectClassification.VS2010Project:
this.Log.LogMessage(MessageImportance.Low, "Downgrading project \"{0}\".", taskItem.ItemSpec);
- Project project = new Project();
+ var project = new Project();
project.Load(taskItem.ItemSpec);
project.DefaultToolsVersion = "3.5";
@@ -66,7 +85,18 @@ namespace DotNetOpenAuth.BuildTasks {
project.AddNewItem("Reference", "System.Core");
}
- project.Save(taskItem.ItemSpec);
+ // Rewrite ProjectReferences to other renamed projects.
+ BuildItemGroup projectReferences = project.GetEvaluatedItemsByName("ProjectReference");
+ foreach (var mapping in newProjectToOldProjectMapping) {
+ string oldName = Path.GetFileName(mapping.Key);
+ string newName = Path.GetFileName(mapping.Value);
+ foreach (BuildItem projectReference in projectReferences) {
+ projectReference.Include = Regex.Replace(projectReference.Include, oldName, newName, RegexOptions.IgnoreCase);
+ }
+ }
+
+ project.Save(newProjectToOldProjectMapping[taskItem.ItemSpec]);
+ createdProjectFiles.Add(new TaskItem(taskItem) { ItemSpec = newProjectToOldProjectMapping[taskItem.ItemSpec] });
break;
case ProjectClassification.VS2010Solution:
this.Log.LogMessage(MessageImportance.Low, "Downgrading solution \"{0}\".", taskItem.ItemSpec);
@@ -84,7 +114,16 @@ namespace DotNetOpenAuth.BuildTasks {
contents[i] = contents[i].Replace("TargetFrameworkMoniker = \".NETFramework,Version%3Dv", "TargetFramework = \"");
}
- File.WriteAllLines(taskItem.ItemSpec, contents);
+ foreach (var mapping in newProjectToOldProjectMapping) {
+ string oldName = Path.GetFileName(mapping.Key);
+ string newName = Path.GetFileName(mapping.Value);
+ for (int i = 0; i < contents.Length; i++) {
+ contents[i] = Regex.Replace(contents[i], oldName, newName, RegexOptions.IgnoreCase);
+ }
+ }
+
+ File.WriteAllLines(newProjectToOldProjectMapping[taskItem.ItemSpec], contents);
+ createdProjectFiles.Add(new TaskItem(taskItem) { ItemSpec = newProjectToOldProjectMapping[taskItem.ItemSpec] });
break;
default:
this.Log.LogWarning("Unrecognized project type for \"{0}\".", taskItem.ItemSpec);
@@ -92,6 +131,8 @@ namespace DotNetOpenAuth.BuildTasks {
}
}
+ this.DowngradedProjects = createdProjectFiles.ToArray();
+
return !this.Log.HasLoggedErrors;
}