diff options
author | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2011-08-01 20:20:11 +0400 |
---|---|---|
committer | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2011-08-01 20:20:11 +0400 |
commit | 95b5a2414b883fde85301141eb071fbcf6bde33f (patch) | |
tree | 6f31fa45c02ebb3ebbc8e5e46e931422a8c3de3e /main | |
parent | ce3476a5218fade5079e2e26e5250aaf73fe974f (diff) |
[Project] Make MSBuild more consistent with VS
Default values of framework is now format specific and
flavor specific. Assembly references without a specific
version now write a partial assembly name.
Diffstat (limited to 'main')
11 files changed, 108 insertions, 44 deletions
diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetAppProject.cs b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetAppProject.cs index b49b651352..e82e080004 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetAppProject.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetAppProject.cs @@ -51,7 +51,7 @@ using MonoDevelop.Projects.Dom.Parser; namespace MonoDevelop.AspNet { [DataInclude (typeof(AspNetAppProjectConfiguration))] - public class AspNetAppProject : DotNetProject + public class AspNetAppProject : DotNetAssemblyProject { [ItemProperty("XspParameters", IsExternal=true)] protected XspParameters xspParameters = new XspParameters (); @@ -128,12 +128,6 @@ namespace MonoDevelop.AspNet } } - public override bool SupportsFramework (TargetFramework framework) - { - //only support 1.1, 2.0, 3.5, 4.0 etc, not monotouch, moonlight and so on - return framework.Id.Identifier == TargetFrameworkMoniker.ID_NET_FRAMEWORK && base.SupportsFramework (framework); - } - #endregion #region constructors diff --git a/main/src/addins/MonoDevelop.Moonlight/MonoDevelop.Moonlight/MoonlightProject.cs b/main/src/addins/MonoDevelop.Moonlight/MonoDevelop.Moonlight/MoonlightProject.cs index 6af1803148..c661ff4f2c 100644 --- a/main/src/addins/MonoDevelop.Moonlight/MonoDevelop.Moonlight/MoonlightProject.cs +++ b/main/src/addins/MonoDevelop.Moonlight/MonoDevelop.Moonlight/MoonlightProject.cs @@ -96,9 +96,14 @@ namespace MonoDevelop.Moonlight generateSilverlightManifest = true; } - public override TargetFrameworkMoniker GetDefaultTargetFrameworkId () + public override TargetFrameworkMoniker GetDefaultTargetFrameworkId (FileFormat format) { - return new TargetFrameworkMoniker ("Silverlight", "4.0"); + switch (format.Id) { + case "MSBuild08": + return new TargetFrameworkMoniker ("Silverlight", "3.0"); + default: + return new TargetFrameworkMoniker ("Silverlight", "4.0"); + } } public override SolutionItemConfiguration CreateConfiguration (string name) diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/DotNetProjectNode.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/DotNetProjectNode.cs index ce5eea65df..1b0759072d 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/DotNetProjectNode.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/DotNetProjectNode.cs @@ -59,11 +59,11 @@ namespace MonoDevelop.Projects.Extensions return false; } - public override SolutionEntityItem LoadSolutionItem (IProgressMonitor monitor, string fileName, string itemGuid) + public override SolutionEntityItem LoadSolutionItem (IProgressMonitor monitor, string fileName, MSBuildFileFormat expectedFormat, string itemGuid) { MSBuildProjectHandler handler = CreateHandler<MSBuildProjectHandler> (fileName, itemGuid); handler.SetCustomResourceHandler (GetResourceHandler ()); - return handler.Load (monitor, fileName, language, null); + return handler.Load (monitor, fileName, expectedFormat, language, null); } public IResourceHandler GetResourceHandler () diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/ItemTypeNode.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/ItemTypeNode.cs index ba4b9c1829..7608071bee 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/ItemTypeNode.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/ItemTypeNode.cs @@ -118,6 +118,6 @@ namespace MonoDevelop.Projects.Extensions return h; } - public abstract SolutionEntityItem LoadSolutionItem (IProgressMonitor monitor, string fileName, string itemGuid); + public abstract SolutionEntityItem LoadSolutionItem (IProgressMonitor monitor, string fileName, MSBuildFileFormat expectedFormat, string itemGuid); } } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/SolutionItemNode.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/SolutionItemNode.cs index 044301efc6..1dc81dafca 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/SolutionItemNode.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/SolutionItemNode.cs @@ -48,10 +48,10 @@ namespace MonoDevelop.Projects.Extensions return ItemType != null && ItemType.IsAssignableFrom (item.GetType ()); } - public override SolutionEntityItem LoadSolutionItem (IProgressMonitor monitor, string fileName, string itemGuid) + public override SolutionEntityItem LoadSolutionItem (IProgressMonitor monitor, string fileName, MSBuildFileFormat expectedFormat, string itemGuid) { MSBuildProjectHandler handler = CreateHandler<MSBuildProjectHandler> (fileName, itemGuid); - return handler.Load (monitor, fileName, null, ItemType); + return handler.Load (monitor, fileName, expectedFormat, null, ItemType); } } -} +}
\ No newline at end of file diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildFileFormat.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildFileFormat.cs index 973edbf848..a562b8208b 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildFileFormat.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildFileFormat.cs @@ -36,7 +36,7 @@ using MonoDevelop.Projects.Extensions; namespace MonoDevelop.Projects.Formats.MSBuild { - class MSBuildFileFormat: IFileFormat + public abstract class MSBuildFileFormat: IFileFormat { SlnFileFormat slnFileFormat = new SlnFileFormat (); string productVersion; @@ -160,7 +160,7 @@ namespace MonoDevelop.Projects.Formats.MSBuild if (slnFileFormat.CanReadFile (file, this)) return slnFileFormat.ReadFile (file, this, monitor); else - return MSBuildProjectService.LoadItem (monitor, file, null, null); + return MSBuildProjectService.LoadItem (monitor, file, null, null, null); }
public List<FilePath> GetItemFiles (object obj) @@ -245,6 +245,21 @@ namespace MonoDevelop.Projects.Formats.MSBuild } return string.Empty; } + + public abstract string Id { get; } + + public static MSBuildFileFormat GetFormatForToolsVersion (string toolsVersion) + { + switch (toolsVersion) { + case "2.0": + return new MSBuildFileFormatVS05 (); + case "3.5": + return new MSBuildFileFormatVS08 (); + case "4.0": + return new MSBuildFileFormatVS10 (); + } + throw new Exception ("Unknown ToolsVersion '" + toolsVersion + "'"); + } } class MSBuildFileFormatVS05: MSBuildFileFormat @@ -261,6 +276,10 @@ namespace MonoDevelop.Projects.Formats.MSBuild public MSBuildFileFormatVS05 (): base (Version, toolsVersion, slnVersion, productComment, frameworkVersions, supportsMonikers) { } + + public override string Id { + get { return "MSBuild05"; } + } } class MSBuildFileFormatVS08: MSBuildFileFormat @@ -282,6 +301,10 @@ namespace MonoDevelop.Projects.Formats.MSBuild public MSBuildFileFormatVS08 (): base (Version, toolsVersion, slnVersion, productComment, frameworkVersions, supportsMonikers) { } + + public override string Id { + get { return "MSBuild08"; } + } } class MSBuildFileFormatVS10: MSBuildFileFormat @@ -301,5 +324,9 @@ namespace MonoDevelop.Projects.Formats.MSBuild public MSBuildFileFormatVS10 (): base (Version, toolsVersion, slnVersion, productComment, frameworkVersions, supportsMonikers) { } + + public override string Id { + get { return "MSBuild10"; } + } } } diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectHandler.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectHandler.cs index 134d6e149d..6e1ef2a5d0 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectHandler.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectHandler.cs @@ -228,7 +228,7 @@ namespace MonoDevelop.Projects.Formats.MSBuild return FileService.AbsoluteToRelativePath (basePath, path); } - public SolutionEntityItem Load (IProgressMonitor monitor, string fileName, string language, Type itemClass) + public SolutionEntityItem Load (IProgressMonitor monitor, string fileName, MSBuildFileFormat expectedFormat, string language, Type itemClass) { timer = Counters.ReadMSBuildProject.BeginTiming (); @@ -237,6 +237,23 @@ namespace MonoDevelop.Projects.Formats.MSBuild fileContent = File.ReadAllText (fileName); p.LoadXml (fileContent); + //determine the file format + MSBuildFileFormat format = null; + if (expectedFormat != null) { + if (p.ToolsVersion != expectedFormat.ToolsVersion) { + monitor.ReportWarning (GettextCatalog.GetString ("Project '{0}' has different ToolsVersion than the containing solution.")); + } else { + format = expectedFormat; + } + } + if (format == null) { + string toolsVersion = p.ToolsVersion; + if (string.IsNullOrEmpty (toolsVersion)) + toolsVersion = "2.0"; + format = MSBuildFileFormat.GetFormatForToolsVersion (toolsVersion); + } + this.SetTargetFormat (format); + timer.Trace ("Read project guids"); MSBuildPropertySet globalGroup = p.GetGlobalPropertyGroup (); @@ -340,6 +357,11 @@ namespace MonoDevelop.Projects.Formats.MSBuild return item; } + FileFormat GetFileFormat () + { + return new FileFormat (TargetFormat, TargetFormat.Id, TargetFormat.Name); + } + void Load (IProgressMonitor monitor, MSBuildProject msproject) { timer.Trace ("Initialize serialization"); @@ -379,7 +401,7 @@ namespace MonoDevelop.Projects.Formats.MSBuild //determine the default target framework from the project type's default //overridden by the components in the project - var def = dotNetProject.GetDefaultTargetFrameworkId (); + var def = dotNetProject.GetDefaultTargetFrameworkId (GetFileFormat ()); targetFx = new TargetFrameworkMoniker ( string.IsNullOrEmpty (frameworkIdentifier)? def.Identifier : frameworkIdentifier, string.IsNullOrEmpty (frameworkVersion)? def.Version : frameworkVersion, @@ -866,16 +888,13 @@ namespace MonoDevelop.Projects.Formats.MSBuild if (dotNetProject != null) { var moniker = dotNetProject.TargetFramework.Id; bool supportsMultipleFrameworks = TargetFormat.FrameworkVersions.Length > 0; - var def = dotNetProject.GetDefaultTargetFrameworkId (); + var def = dotNetProject.GetDefaultTargetFrameworkId (GetFileFormat ()); bool isDefaultIdentifier = def.Identifier == moniker.Identifier; bool isDefaultVersion = isDefaultIdentifier && def.Version == moniker.Version; bool isDefaultProfile = isDefaultVersion && def.Profile == moniker.Profile; - - //HACK: default needs to be format dependent, so always write it for now - isDefaultVersion = false; // If the format only supports one fx version, or the version is the default, there is no need to store it - if (/*!isDefaultVersion &&*/ supportsMultipleFrameworks) + if (!isDefaultVersion && supportsMultipleFrameworks) SetGroupProperty (globalGroup, "TargetFrameworkVersion", "v" + moniker.Version, false); else globalGroup.RemoveProperty ("TargetFrameworkVersion"); @@ -1067,7 +1086,12 @@ namespace MonoDevelop.Projects.Formats.MSBuild else { if (File.Exists (pref.Reference)) { try { - asm = AssemblyName.GetAssemblyName (pref.Reference).FullName; + var aname = AssemblyName.GetAssemblyName (pref.Reference); + if (pref.SpecificVersion) { + asm = aname.FullName; + } else { + asm = aname.Name; + } } catch (Exception ex) { string msg = string.Format ("Could not get full name for assembly '{0}'.", pref.Reference); monitor.ReportWarning (msg); @@ -1083,12 +1107,15 @@ namespace MonoDevelop.Projects.Formats.MSBuild asm = Path.GetFileNameWithoutExtension (pref.Reference); buildItem = AddOrGetBuildItem (msproject, oldItems, "Reference", asm); - if (!pref.SpecificVersion) + + if (!pref.SpecificVersion && ReferenceStringHasVersion (asm)) { buildItem.SetMetadata ("SpecificVersion", "False"); - else + } else { buildItem.UnsetMetadata ("SpecificVersion"); + } + buildItem.SetMetadata ("HintPath", hintPath); - if (!pref.LocalCopy) + if (!pref.LocalCopy && pref.CanSetLocalCopy) buildItem.SetMetadata ("Private", "False"); else buildItem.UnsetMetadata ("Private"); @@ -1215,8 +1242,9 @@ namespace MonoDevelop.Projects.Formats.MSBuild oldItems [key] = itemInfo; } return itemInfo.Item; - } else + } else { return msproject.AddNewItem (name, include); + } } DataItem ReadPropertyGroupMetadata (DataSerializer ser, MSBuildPropertySet propGroup, object dataItem) diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectService.cs index b79358c2fc..5667091222 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectService.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/MSBuildProjectService.cs @@ -84,18 +84,18 @@ namespace MonoDevelop.Projects.Formats.MSBuild }; } - public static SolutionEntityItem LoadItem (IProgressMonitor monitor, string fileName, string typeGuid, string itemGuid) + public static SolutionEntityItem LoadItem (IProgressMonitor monitor, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid) { foreach (ItemTypeNode node in GetItemTypeNodes ()) { if (node.CanHandleFile (fileName, typeGuid)) - return node.LoadSolutionItem (monitor, fileName, itemGuid); + return node.LoadSolutionItem (monitor, fileName, expectedFormat, itemGuid); } if (string.IsNullOrEmpty (typeGuid) && IsProjectSubtypeFile (fileName)) { typeGuid = LoadProjectTypeGuids (fileName); foreach (ItemTypeNode node in GetItemTypeNodes ()) { if (node.CanHandleFile (fileName, typeGuid)) - return node.LoadSolutionItem (monitor, fileName, itemGuid); + return node.LoadSolutionItem (monitor, fileName, expectedFormat, itemGuid); } } @@ -689,10 +689,10 @@ namespace MonoDevelop.Projects.Formats.MSBuild return true; } - public override SolutionEntityItem LoadSolutionItem (IProgressMonitor monitor, string fileName, string itemGuid) + public override SolutionEntityItem LoadSolutionItem (IProgressMonitor monitor, string fileName, MSBuildFileFormat expectedFormat, string itemGuid) { MSBuildProjectHandler handler = new MSBuildProjectHandler (Guid, Import, itemGuid); - return handler.Load (monitor, fileName, null, null); + return handler.Load (monitor, fileName, expectedFormat, null, null); } } -} +}
\ No newline at end of file diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFileFormat.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFileFormat.cs index aa4329ece5..d51321b9c1 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFileFormat.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MSBuild/SlnFileFormat.cs @@ -44,7 +44,7 @@ using MonoDevelop.Core.ProgressMonitoring; namespace MonoDevelop.Projects.Formats.MSBuild { - internal class SlnFileFormat + public class SlnFileFormat { public string GetValidFormatName (object obj, string fileName, MSBuildFileFormat format) { @@ -741,7 +741,7 @@ namespace MonoDevelop.Projects.Formats.MSBuild try { item = ProjectExtensionUtil.LoadSolutionItem (monitor, projectPath, delegate { - return MSBuildProjectService.LoadItem (monitor, projectPath, projTypeGuid, projectGuid); + return MSBuildProjectService.LoadItem (monitor, projectPath, format, projTypeGuid, projectGuid); }); if (item == null) { diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetAssemblyProject.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetAssemblyProject.cs index 3bf0955820..0bc016e80a 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetAssemblyProject.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetAssemblyProject.cs @@ -57,6 +57,19 @@ namespace MonoDevelop.Projects return base.SupportsFramework (framework); } + public override TargetFrameworkMoniker GetDefaultTargetFrameworkId (FileFormat format) + { + switch (format.Id) { + case "MSBuild05": + return TargetFrameworkMoniker.NET_2_0; + case "MSBuild08": + return TargetFrameworkMoniker.NET_3_5; + case "MSBuild10": + return TargetFrameworkMoniker.NET_4_0; + } + return Services.ProjectService.DefaultTargetFramework.Id; + } + protected override string GetDefaultTargetPlatform (ProjectCreateInformation projectCreateInfo) { if (CompileTarget == CompileTarget.Library) diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetProject.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetProject.cs index 7c6aa8c7d1..8504568b49 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetProject.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetProject.cs @@ -284,7 +284,7 @@ namespace MonoDevelop.Projects public TargetFramework TargetFramework { get { if (targetFramework == null) { - var id = newProjectTargetFrameworkId ?? GetDefaultTargetFrameworkId (); + var id = newProjectTargetFrameworkId ?? GetDefaultTargetFrameworkId (FileFormat); targetFramework = Runtime.SystemAssemblyService.GetTargetFramework (id); } return targetFramework; @@ -293,7 +293,7 @@ namespace MonoDevelop.Projects if (!SupportsFramework (value)) throw new ArgumentException ("Project does not support framework '" + value.Id.ToString () +"'"); if (value == null) - value = Runtime.SystemAssemblyService.GetTargetFramework (GetDefaultTargetFrameworkId ()); + value = Runtime.SystemAssemblyService.GetTargetFramework (GetDefaultTargetFrameworkId (FileFormat)); if (value.Id == targetFramework.Id) return; bool updateReferences = targetFramework != null; @@ -308,10 +308,7 @@ namespace MonoDevelop.Projects get { return Runtime.SystemAssemblyService.DefaultRuntime; } } - public virtual TargetFrameworkMoniker GetDefaultTargetFrameworkId () - { - return Services.ProjectService.DefaultTargetFramework.Id; - } + public abstract TargetFrameworkMoniker GetDefaultTargetFrameworkId (FileFormat format); public IAssemblyContext AssemblyContext { get { @@ -745,7 +742,7 @@ namespace MonoDevelop.Projects // Make sure the fx version is sorted out before saving // to avoid changes in project references while saving if (targetFramework == null) - targetFramework = Runtime.SystemAssemblyService.GetTargetFramework (GetDefaultTargetFrameworkId ()); + targetFramework = Runtime.SystemAssemblyService.GetTargetFramework (GetDefaultTargetFrameworkId (FileFormat)); base.OnSave (monitor); } |