From e1b22249418126b333241fdbfd0310794016f5e9 Mon Sep 17 00:00:00 2001 From: Mikayla Hutchinson Date: Tue, 17 Apr 2018 15:54:33 -0400 Subject: Clean up MSBuildFileFormat --- .../MSBuildFileFormat.cs | 174 +++++++-------------- .../MonoDevelop.Projects.MSBuild/SlnFileFormat.cs | 4 +- .../MonoDevelop.Projects/ProjectConvertTool.cs | 18 +-- .../SelectFileFormatDialog.cs | 4 +- .../ExportSolutionDialog.cs | 11 +- 5 files changed, 74 insertions(+), 137 deletions(-) (limited to 'main/src/core') diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildFileFormat.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildFileFormat.cs index d3084e8e19..e35886fdfe 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildFileFormat.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildFileFormat.cs @@ -67,21 +67,19 @@ namespace MonoDevelop.Projects.MSBuild return GetSupportedFormats ().Where (f => f.CanWriteFile (targetItem)); } - public static MSBuildFileFormat DefaultFormat { - get { return VS2012; } - } + public static MSBuildFileFormat DefaultFormat => VS2012; - public string Name { - get { return "MSBuild"; } - } + [Obsolete ("Use ProductDescription or ID")] + public string Name => "MSBuild"; + [Obsolete] public abstract Version Version { get; } internal SlnFileFormat SlnFileFormat { get { return slnFileFormat; } } - public bool SupportsMonikers { get { return SupportedFrameworks == null; } } + public bool SupportsMonikers => SupportedFrameworks == null; public static bool ToolsSupportMonikers (string toolsVersion) { @@ -198,8 +196,16 @@ namespace MonoDevelop.Projects.MSBuild public virtual string DefaultSchemaVersion { get { return null; } } + /// + /// Product description for display in UI + /// public abstract string ProductDescription { get; } + /// + /// Product description for comment in new sln files + /// + public virtual string ProductDescriptionComment => ProductDescription; + public virtual TargetFrameworkMoniker[] SupportedFrameworks { get { return null; } } @@ -226,49 +232,39 @@ namespace MonoDevelop.Projects.MSBuild public abstract string Id { get; } } - - class MSBuildFileFormatVS05: MSBuildFileFormat - { - static readonly TargetFrameworkMoniker[] supportedFrameworks = { - TargetFrameworkMoniker.NET_2_0, - }; - - public override string Id { - get { return "MSBuild05"; } - } - - public override Version Version { - get { return new Version ("2005"); } - } - - public override string DefaultProductVersion { - get { return "8.0.50727"; } - } - - public override string DefaultToolsVersion { - get { return "2.0"; } - } - public override string DefaultSchemaVersion { - get { return "2.0"; } - } + class MSBuildFileFormatVS05 : MSBuildFileFormat + { + public override string Id => "MSBuild05"; - public override string SlnVersion { - get { return "9.00"; } - } + [Obsolete("Unused")] + public override Version Version => new Version ("2005"); - public override string ProductDescription { - get { return "Visual Studio 2005"; } - } + public override string DefaultProductVersion => "8.0.50727"; + public override string DefaultToolsVersion => "2.0"; + public override string DefaultSchemaVersion => "2.0"; + public override string SlnVersion => "9.00"; + public override string ProductDescription => "Visual Studio 2005"; - public override TargetFrameworkMoniker[] SupportedFrameworks { - get { return supportedFrameworks; } - } + public override TargetFrameworkMoniker [] SupportedFrameworks { get; } = { + TargetFrameworkMoniker.NET_2_0, + }; } class MSBuildFileFormatVS08: MSBuildFileFormat { - static readonly TargetFrameworkMoniker[] supportedFrameworks = { + public override string Id => "MSBuild08"; + + [Obsolete ("Unused")] + public override Version Version => new Version ("2008"); + + public override string DefaultProductVersion => "9.0.21022"; + public override string DefaultToolsVersion => "3.5"; + public override string DefaultSchemaVersion => "2.0"; + public override string SlnVersion => "10.00"; + public override string ProductDescription => "Visual Studio 2008"; + + public override TargetFrameworkMoniker [] SupportedFrameworks { get; } = { TargetFrameworkMoniker.NET_2_0, TargetFrameworkMoniker.NET_3_0, TargetFrameworkMoniker.NET_3_5, @@ -277,97 +273,45 @@ namespace MonoDevelop.Projects.MSBuild TargetFrameworkMoniker.MONOTOUCH_1_0, }; - public override string Id { - get { return "MSBuild08"; } - } - - public override Version Version { - get { return new Version ("2008"); } - } - - public override string DefaultProductVersion { - get { return "9.0.21022"; } - } - - public override string DefaultToolsVersion { - get { return "3.5"; } - } - - public override string DefaultSchemaVersion { - get { return "2.0"; } - } - - public override string SlnVersion { - get { return "10.00"; } - } - - public override string ProductDescription { - get { return "Visual Studio 2008"; } - } - - public override TargetFrameworkMoniker[] SupportedFrameworks { - get { return supportedFrameworks; } - } } class MSBuildFileFormatVS10: MSBuildFileFormat { - public override string Id { - get { return "MSBuild10"; } - } - - public override Version Version { - get { return new Version ("2010"); } - } + public override string Id => "MSBuild10"; - //WTF VS - public override string DefaultProductVersion { - get { return "8.0.30703"; } - } - - public override string DefaultSchemaVersion { - get { return "2.0"; } - } - - public override string DefaultToolsVersion { - get { return "4.0"; } - } - - public override string SlnVersion { - get { return "11.00"; } - } + [Obsolete ("Unused")] + public override Version Version => new Version ("2010"); - public override string ProductDescription { - get { return "Visual Studio 2010"; } - } + public override string DefaultProductVersion => "8.0.30703"; + public override string DefaultSchemaVersion => "2.0"; + public override string DefaultToolsVersion => "4.0"; + public override string SlnVersion => "11.00"; + public override string ProductDescription => "Visual Studio 2010"; } // this is actually VS2010 SP1 and later class MSBuildFileFormatVS12: MSBuildFileFormat { - public override string Id { - get { return "MSBuild12"; } - } + public override string Id => "MSBuild12"; - public override Version Version { - get { return new Version ("2012"); } - } + [Obsolete ("Unused")] + public override Version Version => new Version ("2012"); - public override string DefaultToolsVersion { - get { return "4.0"; } - } + // This is mostly irrelevant, the builder always uses the latest + // tools version. It's only used for new projects created with + // the old project template engine. + public override string DefaultToolsVersion => "4.0"; - public override string SlnVersion { - get { return "12.00"; } - } + public override string SlnVersion => "12.00"; - public override string ProductDescription { - get { return "Visual Studio 15"; } - } + public override string ProductDescription => "Visual Studio 2012+"; + + // This matches the value used by VS 2017 + public override string ProductDescriptionComment => "Visual Studio 15"; protected override bool SupportsToolsVersion (string version) { - return version == "4.0" || version == "12.0" || version == "14.0" || version == "15.0"; + return Version.TryParse (version, out Version v) && v <= new Version (15, 0); } } } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/SlnFileFormat.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/SlnFileFormat.cs index af80a19a13..be5910cc7f 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/SlnFileFormat.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/SlnFileFormat.cs @@ -113,9 +113,9 @@ namespace MonoDevelop.Projects.MSBuild sln.FormatVersion = format.SlnVersion; - // Don't modify the product description if it already has a value + // Don't modify the product description comment if it already has a value if (string.IsNullOrEmpty (sln.ProductDescription)) - sln.ProductDescription = format.ProductDescription; + sln.ProductDescription = format.ProductDescriptionComment; solution.WriteSolution (monitor, sln); diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectConvertTool.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectConvertTool.cs index dddda00224..9f9d8dbf85 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectConvertTool.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectConvertTool.cs @@ -62,18 +62,18 @@ namespace MonoDevelop.Projects string projectFile = null; string destPath = null; - string formatName = null; + string formatId = null; bool formatList = false; List projects = new List (); string[] itemsToExport = null; foreach (string s in arguments) { - if (s.StartsWith ("-d:")) + if (s.StartsWith ("-d:", StringComparison.Ordinal)) destPath = s.Substring (3); - else if (s.StartsWith ("-f:")) - formatName = s.Substring (3); - else if (s.StartsWith ("-p:")) + else if (s.StartsWith ("-f:", StringComparison.Ordinal)) + formatId = s.Substring (3); + else if (s.StartsWith ("-p:", StringComparison.Ordinal)) projects.Add (s.Substring (3)); else if (s == "-l") formatList = true; @@ -142,11 +142,11 @@ namespace MonoDevelop.Projects MSBuildFileFormat format = null; - if (formatName == null || formatList) { + if (formatId == null || formatList) { Console.WriteLine (); Console.WriteLine ("Target formats:"); for (int n=0; n