Browse Source
Allow picking the profile (set of target frameworks) in project upgrade view.pull/24/merge
13 changed files with 352 additions and 56 deletions
@ -0,0 +1,34 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.IO; |
||||||
|
using ICSharpCode.Core; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Project.PortableLibrary |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Shows a message box if the portable library is not installed.
|
||||||
|
/// </summary>
|
||||||
|
public class CheckPortableLibraryInstalled : AbstractCommand |
||||||
|
{ |
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
if (!ProfileList.IsPortableLibraryInstalled()) { |
||||||
|
using (ToolNotFoundDialog dlg = new ToolNotFoundDialog( |
||||||
|
"Could not find Portable Class Library Tools." + Environment.NewLine + Environment.NewLine + |
||||||
|
"To install the Portable Class Library Tools without installing Visual Studio, save the download file (PortableLibraryTools.exe) on your computer, and run the installation program from a Command Prompt window. Include the /buildmachine switch on the command line.", |
||||||
|
"http://go.microsoft.com/fwlink/?LinkId=210823" |
||||||
|
)) { |
||||||
|
// our message is long, so make the window bigger than usual
|
||||||
|
dlg.Width += 70; |
||||||
|
dlg.Height += 70; |
||||||
|
dlg.ShowDialog(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,48 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.IO; |
||||||
|
using System.Linq; |
||||||
|
using System.Xml; |
||||||
|
using System.Xml.Linq; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Project.PortableLibrary |
||||||
|
{ |
||||||
|
public class PortableTargetFramework : TargetFramework |
||||||
|
{ |
||||||
|
public readonly string TargetFrameworkVersion; |
||||||
|
public readonly string TargetFrameworkProfile; |
||||||
|
|
||||||
|
public PortableTargetFramework(string targetFrameworkVersion, string targetFrameworkProfile) |
||||||
|
: base(targetFrameworkVersion + "-" + targetFrameworkProfile, ".NET Portable Subset (" + targetFrameworkVersion + "-" + targetFrameworkProfile + ")") |
||||||
|
{ |
||||||
|
this.TargetFrameworkVersion = targetFrameworkVersion; |
||||||
|
this.TargetFrameworkProfile = targetFrameworkProfile; |
||||||
|
this.MinimumMSBuildVersion = new Version(4, 0); |
||||||
|
} |
||||||
|
|
||||||
|
public PortableTargetFramework(Profile profile) |
||||||
|
: base(profile.TargetFrameworkVersion + "-" + profile.TargetFrameworkProfile, profile.DisplayName) |
||||||
|
{ |
||||||
|
this.TargetFrameworkVersion = profile.TargetFrameworkVersion; |
||||||
|
this.TargetFrameworkProfile = profile.TargetFrameworkProfile; |
||||||
|
this.MinimumMSBuildVersion = new Version(4, 0); |
||||||
|
} |
||||||
|
|
||||||
|
public override bool Equals(object obj) |
||||||
|
{ |
||||||
|
PortableTargetFramework other = obj as PortableTargetFramework; |
||||||
|
if (other == null) |
||||||
|
return false; |
||||||
|
return this.TargetFrameworkVersion == other.TargetFrameworkVersion && this.TargetFrameworkProfile == other.TargetFrameworkProfile; |
||||||
|
} |
||||||
|
|
||||||
|
public override int GetHashCode() |
||||||
|
{ |
||||||
|
return this.TargetFrameworkVersion.GetHashCode() ^ this.TargetFrameworkProfile.GetHashCode(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,105 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.IO; |
||||||
|
using System.Linq; |
||||||
|
using System.Xml; |
||||||
|
using System.Xml.Linq; |
||||||
|
|
||||||
|
namespace ICSharpCode.SharpDevelop.Project.PortableLibrary |
||||||
|
{ |
||||||
|
public class ProfileList |
||||||
|
{ |
||||||
|
internal static string GetPortableLibraryPath() |
||||||
|
{ |
||||||
|
string programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); |
||||||
|
return Path.Combine(programFiles, @"Reference Assemblies\Microsoft\Framework\.NETPortable"); |
||||||
|
} |
||||||
|
|
||||||
|
public static bool IsPortableLibraryInstalled() |
||||||
|
{ |
||||||
|
return Directory.Exists(GetPortableLibraryPath()); |
||||||
|
} |
||||||
|
|
||||||
|
#region LoadProfiles
|
||||||
|
static readonly Lazy<ProfileList> instance = new Lazy<ProfileList>(LoadProfiles); |
||||||
|
|
||||||
|
public static ProfileList Instance { |
||||||
|
get { return instance.Value; } |
||||||
|
} |
||||||
|
|
||||||
|
internal static ProfileList LoadProfiles() |
||||||
|
{ |
||||||
|
ProfileList result = new ProfileList(); |
||||||
|
string path = GetPortableLibraryPath(); |
||||||
|
result.LoadProfiles("v4.0", Path.Combine(path, @"v4.0\Profile")); |
||||||
|
result.LoadProfiles("v4.5", Path.Combine(path, @"v4.5\Profile")); |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
List<Profile> list = new List<Profile>(); |
||||||
|
|
||||||
|
void LoadProfiles(string targetFrameworkVersion, string profilesDir) |
||||||
|
{ |
||||||
|
string[] profileDirs; |
||||||
|
try { |
||||||
|
profileDirs = Directory.GetDirectories(profilesDir); |
||||||
|
} catch (IOException) { |
||||||
|
return; |
||||||
|
} catch (UnauthorizedAccessException) { |
||||||
|
return; |
||||||
|
} |
||||||
|
foreach (string profileDir in profileDirs) { |
||||||
|
string targetFrameworkProfile = Path.GetFileName(profileDir); |
||||||
|
var profile = Profile.LoadProfile(targetFrameworkVersion, targetFrameworkProfile, profileDir); |
||||||
|
if (profile != null) |
||||||
|
list.Add(profile); |
||||||
|
} |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
public IEnumerable<Profile> AllProfiles { |
||||||
|
get { return list; } |
||||||
|
} |
||||||
|
|
||||||
|
public IEnumerable<SupportedFramework> AllFrameworks { |
||||||
|
get { return list.SelectMany(p => p.SupportedFrameworks).Distinct(); } |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves all profiles that support all of the given frameworks.
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<Profile> GetProfiles(IList<SupportedFramework> frameworks) |
||||||
|
{ |
||||||
|
if (frameworks == null) |
||||||
|
throw new ArgumentNullException("frameworks"); |
||||||
|
return list.Where(p => p.Supports(frameworks)); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves the most specific profile that supports all of the given frameworks.
|
||||||
|
/// Returns null if no profile supports the given frameworks.
|
||||||
|
/// </summary>
|
||||||
|
public Profile GetBestProfile(IList<SupportedFramework> frameworks) |
||||||
|
{ |
||||||
|
var candidates = GetProfiles(frameworks).ToList(); |
||||||
|
for (int i = candidates.Count - 1; i >= 0; i--) { |
||||||
|
for (int j = 0; j < candidates.Count; j++) { |
||||||
|
if (i != j) { |
||||||
|
if (candidates[i].Supports(candidates[j].SupportedFrameworks)) { |
||||||
|
// i is less specific than j, so remove it
|
||||||
|
candidates.RemoveAt(i); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
// If the portable library profiles are specified properly, there should be at most one result,
|
||||||
|
// so we'll just return that.
|
||||||
|
return candidates.FirstOrDefault(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue