Skip to content
This repository was archived by the owner on Mar 20, 2019. It is now read-only.

Commit cb70c1e

Browse files
committed
Sample projects are now downgraded from VS2010 to VS2008 while creating a drop.
1 parent 761db79 commit cb70c1e

6 files changed

Lines changed: 108 additions & 1 deletion

File tree

build.proj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,13 +423,15 @@
423423
<Purge Directories="$(DropDirectory)" IntendedFiles="@(AllDropTargets)" />
424424
<!-- fix up the samples so that they will compile right out of the drop -->
425425
<ItemGroup>
426-
<SampleProjectTargets Include="$(DropSamplesDirectory)**\*.csproj" />
426+
<SampleProjectTargets Include="$(DropSamplesDirectory)**\*.*proj" />
427+
<SampleSolutionTargets Include="$(DropSamplesDirectory)**\*.sln" />
427428
</ItemGroup>
428429
<FixupShippingToolSamples Projects="@(DropSamplesToolsProjects)"
429430
RemoveImportsStartingWith="%24(ProjectRoot)tools\"
430431
AddReferences="Microsoft.Contracts"/>
431432
<ChangeProjectReferenceToAssemblyReference Projects="@(SampleProjectTargets)"
432433
ProjectReference="..\..\src\$(ProductName)\$(ProductName).csproj" Reference="..\..\Bin\$(ProductName).dll" />
434+
<DowngradeProjects Projects="@(SampleProjectTargets);@(SampleSolutionTargets)" />
433435
</Target>
434436

435437
<Target Name="Drop" DependsOnTargets="DropLayout">

lib/DotNetOpenAuth.BuildTasks.dll

3 KB
Binary file not shown.

lib/DotNetOpenAuth.BuildTasks.pdb

4 KB
Binary file not shown.

lib/DotNetOpenAuth.BuildTasks.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@
2828
<UsingTask AssemblyFile="$(ProjectRoot)\lib\DotNetOpenAuth.BuildTasks.dll" TaskName="Purge" />
2929
<UsingTask AssemblyFile="$(ProjectRoot)\lib\DotNetOpenAuth.BuildTasks.dll" TaskName="FixupShippingToolSamples" />
3030
<UsingTask AssemblyFile="$(ProjectRoot)\lib\DotNetOpenAuth.BuildTasks.dll" TaskName="Publicize" />
31+
<UsingTask AssemblyFile="$(ProjectRoot)\lib\DotNetOpenAuth.BuildTasks.dll" TaskName="DowngradeProjects" />
3132

3233
</Project>

src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
<Compile Include="CreateWebApplication.cs" />
105105
<Compile Include="DeleteWebApplication.cs" />
106106
<Compile Include="DiscoverProjectTemplates.cs" />
107+
<Compile Include="DowngradeProjects.cs" />
107108
<Compile Include="ECMAScriptPacker.cs" />
108109
<Compile Include="FilterItems.cs" />
109110
<Compile Include="FixupReferenceHintPaths.cs" />
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//-----------------------------------------------------------------------
2+
// <copyright file="DowngradeProjects.cs" company="Andrew Arnott">
3+
// Copyright (c) Andrew Arnott. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------
6+
7+
namespace DotNetOpenAuth.BuildTasks {
8+
using System;
9+
using System.Collections.Generic;
10+
using System.IO;
11+
using System.Linq;
12+
using System.Text;
13+
using Microsoft.Build.BuildEngine;
14+
using Microsoft.Build.Framework;
15+
using Microsoft.Build.Utilities;
16+
17+
/// <summary>
18+
/// Downgrades Visual Studio 2010 solutions and projects so that they load in Visual Studio 2008.
19+
/// </summary>
20+
public class DowngradeProjects : Task {
21+
/// <summary>
22+
/// Gets or sets the projects and solutions to downgrade.
23+
/// </summary>
24+
[Required]
25+
public ITaskItem[] Projects { get; set; }
26+
27+
/// <summary>
28+
/// Executes this instance.
29+
/// </summary>
30+
public override bool Execute() {
31+
foreach (ITaskItem taskItem in this.Projects) {
32+
switch (GetClassification(taskItem)) {
33+
case ProjectClassification.VS2010Project:
34+
this.Log.LogMessage(MessageImportance.Low, "Downgrading project \"{0}\".", taskItem.ItemSpec);
35+
Project project = new Project();
36+
project.Load(taskItem.ItemSpec);
37+
project.DefaultToolsVersion = "3.5";
38+
39+
string projectTypeGuids = project.GetEvaluatedProperty("ProjectTypeGuids");
40+
if (!string.IsNullOrEmpty(projectTypeGuids)) {
41+
projectTypeGuids = projectTypeGuids.Replace("{F85E285D-A4E0-4152-9332-AB1D724D3325}", "{603c0e0b-db56-11dc-be95-000d561079b0}");
42+
project.SetProperty("ProjectTypeGuids", projectTypeGuids);
43+
}
44+
45+
// Web projects usually have an import that includes these substrings
46+
foreach (Import import in project.Imports) {
47+
import.ProjectPath = import.ProjectPath
48+
.Replace("$(MSBuildExtensionsPath32)", "$(MSBuildExtensionsPath)")
49+
.Replace("VisualStudio\\v10.0", "VisualStudio\\v9.0");
50+
}
51+
52+
// VS2010 won't let you have a System.Core reference, but VS2008 requires it.
53+
BuildItemGroup references = project.GetEvaluatedItemsByName("Reference");
54+
if (!references.Cast<BuildItem>().Any(item => item.FinalItemSpec.StartsWith("System.Core", StringComparison.OrdinalIgnoreCase))) {
55+
project.AddNewItem("Reference", "System.Core");
56+
}
57+
58+
project.Save(taskItem.ItemSpec);
59+
break;
60+
case ProjectClassification.VS2010Solution:
61+
this.Log.LogMessage(MessageImportance.Low, "Downgrading solution \"{0}\".", taskItem.ItemSpec);
62+
string[] contents = File.ReadAllLines(taskItem.ItemSpec);
63+
if (contents[1] != "Microsoft Visual Studio Solution File, Format Version 11.00" ||
64+
contents[2] != "# Visual Studio 2010") {
65+
this.Log.LogError("Unrecognized solution file header in \"{0}\".", taskItem.ItemSpec);
66+
break;
67+
}
68+
69+
contents[1] = "Microsoft Visual Studio Solution File, Format Version 10.00";
70+
contents[2] = "# Visual Studio 2008";
71+
72+
for (int i = 3; i < contents.Length; i++) {
73+
contents[i] = contents[i].Replace("TargetFrameworkMoniker = \".NETFramework,Version%3Dv", "TargetFramework = \"");
74+
}
75+
76+
File.WriteAllLines(taskItem.ItemSpec, contents);
77+
break;
78+
default:
79+
this.Log.LogWarning("Unrecognized project type for \"{0}\".", taskItem.ItemSpec);
80+
break;
81+
}
82+
}
83+
84+
return !this.Log.HasLoggedErrors;
85+
}
86+
87+
private static ProjectClassification GetClassification(ITaskItem taskItem) {
88+
if (Path.GetExtension(taskItem.ItemSpec).EndsWith("proj", StringComparison.OrdinalIgnoreCase)) {
89+
return ProjectClassification.VS2010Project;
90+
} else if (Path.GetExtension(taskItem.ItemSpec).Equals(".sln", StringComparison.OrdinalIgnoreCase)) {
91+
return ProjectClassification.VS2010Solution;
92+
} else {
93+
return ProjectClassification.Unrecognized;
94+
}
95+
}
96+
97+
private enum ProjectClassification {
98+
VS2010Project,
99+
VS2010Solution,
100+
Unrecognized,
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)