Skip to content

Commit 9533f64

Browse files
committed
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.
1 parent 3c09e09 commit 9533f64

4 files changed

Lines changed: 49 additions & 4 deletions

File tree

lib/DotNetOpenAuth.BuildTasks.dll

1.5 KB
Binary file not shown.

lib/DotNetOpenAuth.BuildTasks.pdb

2 KB
Binary file not shown.

src/DotNetOpenAuth.BuildTasks/DowngradeProjects.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace DotNetOpenAuth.BuildTasks {
1010
using System.IO;
1111
using System.Linq;
1212
using System.Text;
13+
using System.Text.RegularExpressions;
1314
using Microsoft.Build.BuildEngine;
1415
using Microsoft.Build.Framework;
1516
using Microsoft.Build.Utilities;
@@ -24,6 +25,9 @@ public class DowngradeProjects : Task {
2425
[Required]
2526
public ITaskItem[] Projects { get; set; }
2627

28+
[Output]
29+
public ITaskItem[] DowngradedProjects { get; set; }
30+
2731
/// <summary>
2832
/// Gets or sets a value indicating whether ASP.NET MVC 2 projects are downgraded to MVC 1.0.
2933
/// </summary>
@@ -33,11 +37,26 @@ public class DowngradeProjects : Task {
3337
/// Executes this instance.
3438
/// </summary>
3539
public override bool Execute() {
40+
var newProjectToOldProjectMapping = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
41+
var createdProjectFiles = new List<TaskItem>();
42+
43+
foreach (ITaskItem taskItem in this.Projects) {
44+
switch (GetClassification(taskItem)) {
45+
case ProjectClassification.VS2010Project:
46+
case ProjectClassification.VS2010Solution:
47+
string projectNameForVS2008 = Path.Combine(
48+
Path.GetDirectoryName(taskItem.ItemSpec),
49+
Path.GetFileNameWithoutExtension(taskItem.ItemSpec) + "-vs2008" + Path.GetExtension(taskItem.ItemSpec));
50+
newProjectToOldProjectMapping[taskItem.ItemSpec] = projectNameForVS2008;
51+
break;
52+
}
53+
}
54+
3655
foreach (ITaskItem taskItem in this.Projects) {
3756
switch (GetClassification(taskItem)) {
3857
case ProjectClassification.VS2010Project:
3958
this.Log.LogMessage(MessageImportance.Low, "Downgrading project \"{0}\".", taskItem.ItemSpec);
40-
Project project = new Project();
59+
var project = new Project();
4160
project.Load(taskItem.ItemSpec);
4261
project.DefaultToolsVersion = "3.5";
4362

@@ -66,7 +85,18 @@ public override bool Execute() {
6685
project.AddNewItem("Reference", "System.Core");
6786
}
6887

69-
project.Save(taskItem.ItemSpec);
88+
// Rewrite ProjectReferences to other renamed projects.
89+
BuildItemGroup projectReferences = project.GetEvaluatedItemsByName("ProjectReference");
90+
foreach (var mapping in newProjectToOldProjectMapping) {
91+
string oldName = Path.GetFileName(mapping.Key);
92+
string newName = Path.GetFileName(mapping.Value);
93+
foreach (BuildItem projectReference in projectReferences) {
94+
projectReference.Include = Regex.Replace(projectReference.Include, oldName, newName, RegexOptions.IgnoreCase);
95+
}
96+
}
97+
98+
project.Save(newProjectToOldProjectMapping[taskItem.ItemSpec]);
99+
createdProjectFiles.Add(new TaskItem(taskItem) { ItemSpec = newProjectToOldProjectMapping[taskItem.ItemSpec] });
70100
break;
71101
case ProjectClassification.VS2010Solution:
72102
this.Log.LogMessage(MessageImportance.Low, "Downgrading solution \"{0}\".", taskItem.ItemSpec);
@@ -84,14 +114,25 @@ public override bool Execute() {
84114
contents[i] = contents[i].Replace("TargetFrameworkMoniker = \".NETFramework,Version%3Dv", "TargetFramework = \"");
85115
}
86116

87-
File.WriteAllLines(taskItem.ItemSpec, contents);
117+
foreach (var mapping in newProjectToOldProjectMapping) {
118+
string oldName = Path.GetFileName(mapping.Key);
119+
string newName = Path.GetFileName(mapping.Value);
120+
for (int i = 0; i < contents.Length; i++) {
121+
contents[i] = Regex.Replace(contents[i], oldName, newName, RegexOptions.IgnoreCase);
122+
}
123+
}
124+
125+
File.WriteAllLines(newProjectToOldProjectMapping[taskItem.ItemSpec], contents);
126+
createdProjectFiles.Add(new TaskItem(taskItem) { ItemSpec = newProjectToOldProjectMapping[taskItem.ItemSpec] });
88127
break;
89128
default:
90129
this.Log.LogWarning("Unrecognized project type for \"{0}\".", taskItem.ItemSpec);
91130
break;
92131
}
93132
}
94133

134+
this.DowngradedProjects = createdProjectFiles.ToArray();
135+
95136
return !this.Log.HasLoggedErrors;
96137
}
97138

tools/drop.proj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
$(ProjectRoot)**\*~;
7373
$(ProjectRoot)**\Debug\**;
7474
$(ProjectRoot)**\StyleCop.Cache;
75-
$(ProjectRoot)Samples\_ReSharper.Samples\**;
75+
$(ProjectRoot)Samples\_ReSharper.*\**;
7676
$(ProjectRoot)Samples\**\DotNetOpenAuth.???;
7777
$(ProjectRoot)Samples\**\DotNetOpenAuth.resources.???;
7878
$(ProjectRoot)Samples\**\log4net.???;
@@ -142,6 +142,10 @@
142142
DowngradeMvc2ToMvc1="$(DowngradeMvc2ToMvc1)"
143143
Condition=" '$(DowngradeVS2010ToVS2008)' != 'false' "
144144
/>
145+
<ItemGroup>
146+
<!-- Go snag the newly created files so that .zip file will include them. -->
147+
<AllDropTargets Include="$(DropSamplesDirectory)**\*-vs2008.*" />
148+
</ItemGroup>
145149
</Target>
146150

147151
<Target Name="Build" DependsOnTargets="Layout" Returns="@(RedistributableFiles)">

0 commit comments

Comments
 (0)