From 03146bb32a9cffb8f06320c35adaea785136a3d2 Mon Sep 17 00:00:00 2001 From: ankit Date: Tue, 6 Apr 2010 09:57:58 +0000 Subject: [PATCH] Add support for ToolsVersion and correctly build msbuild+xbuild assemblies for 3.5 and 4.0 profiles. 2010-04-03 Ankit Jain * Makefile: Process tools/xbuild for 3.5 also. In class/Microsoft.Build.Engine: 2010-04-03 Ankit Jain * Makefile: Use the correct assembly name for MS.Build.Utilities* for 3.5 and 4.0 profiles. Copy the .config files for the test assembly. Import tools/xbuild/xbuild_targets.make, which copies the target and tasks file in the correct place, to allow running tests with different toolsversion. * Microsoft.Build.Engine.dll.sources: Add LogExtensions.cs, Toolset.cs, ToolsetDefinitionLocations.cs and ToolsetCollection.cs . * Test/test-config-file-net-3.5: New. * Test/test-config-file-net-4.0: New. In class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine: 2010-04-03 Ankit Jain * BuildEngine.cs: Implement IBuildEngine2 instead of IBuildEngine. * BuildTasks.cs: Use the new extension methods for logging. (InitializeTask): Emit a message informing about the assembly from which the task is being loaded. Emit a useful debug message incase of a InvalidCastException. * Engine.cs: Add missing methods, constructors and properties related to ToolsVersion support. Setup a default set of Toolsets. Keep separate taskdbs' per ToolsVersion. The common tasks would come from different *.tasks file, and use different task assemblies. (DefaultToolsVersion): Correctly set this based on the profile. * LogExtensions.cs: New. Extension methods on Engine, for logging. * Project.cs: Add missing methods/contructors/properties related to ToolsVersion support. Add reserved properties - MSBuildToolsPath and MSBuildToolsVersion . * Toolset.cs: New. * ToolsetCollection.cs: New. * ToolsetDefinitionLocations.cs: New. In class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine: 2010-04-06 Ankit Jain * Consts.cs (ToolsVersionString): New. (GetTasksAsmPath): New. * EngineTest.cs: Use the direct path to the tasks assembly in the UsingTasks. * ProjectTest.cs: Set ToolsVersion to the current profile. In class/Microsoft.Build.Framework: 2010-04-03 Ankit Jain * Makefile: Import tools/xbuild/xbuild_targets.make, which copies the target and tasks file in the correct place, to allow running tests with different toolsversion. * Microsoft.Build.Framework.dll.sources: Add IBuildEngine2.cs . In class/Microsoft.Build.Framework/Microsoft.Build.Framework: 2010-04-03 Ankit Jain * IBuildEngine2.cs: New. In class/Microsoft.Build.Tasks: 2010-04-03 Ankit Jain * Makefile: Import tools/xbuild/xbuild_targets.make, which copies the target and tasks file in the correct place, to allow running tests with different toolsversion. Copy the config file for the test assembly. Clean the generated test.dll . Use the correct target assembly name for 4.0 profile (ms.build.tasks.v4.0.dll), and for Utilities assembly. * Microsoft.Build.Tasks_test.dll.sources: Use Consts.cs from Engine instead of maintaining a copy here. In class/Microsoft.Build.Tasks/Microsoft.Build.Tasks: 2010-04-03 Ankit Jain * Csc.cs: Use dmcs as the compiler for 4.0 profile. * MSBuild.cs (ToolsVersion): New. Use toolsVersion for building. In class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks: 2010-04-06 Ankit Jain * Consts.cs: Remove. * AssignProjectConfigurationTest.cs: * CreateCSharpManifestResourceNameTest.cs: * CreateVisualBasicManifestResourceNameTest.cs: * CreateItemTest.cs: * FindAppConfigFileTest.cs: * RemoveDuplicatesTest.cs: * TaskBatchingTest.cs: * WriteLinesToFileTest.cs: Set the ToolsVersion to match the profile. Use the full path to the tasks assembly for UsingTasks. In class/Microsoft.Build.Utilities: 2010-04-03 Ankit Jain * Makefile: Import tools/xbuild/xbuild_targets.make, which copies the target and tasks file in the correct place, to allow running tests with different toolsversion. Use the correct target assembly name for 4.0 profile. In class/Microsoft.Build.Utilities/Microsoft.Build.Utilities: 2010-04-03 Ankit Jain * TargetDotNetFrameworkVersion.cs: Add Version40 . * Task.cs (BuildEngine2): New. * ToolLocationHelper.cs: Use class/linet_* as the path for the assemblies and targets when running tests. Environment variable TESTING_MONO is set for testing. This allows a 4.0 xbuild to build 2.0/3.5 projects. In tools: 2010-04-03 Ankit Jain * Makefile: Move xbuild from net_4_0_dirs to per_profile_dirs. In tools/xbuild: 2010-04-03 Ankit Jain * Main.cs (Execute): If toolsversion is specified on the command line, then use that. * Parameters.cs: Read toolsversion from the command line ('/tv:..') . * SolutionParser.cs: Infer ToolsVersion from the sln version. Set ToolsVersion property of the MSBuild tasks, in the generated .sln.proj file, for building the projects. * xbuild/Microsoft.Common.tasks: Move to .. * xbuild/2.0/Microsoft.Common.tasks: .. here. * xbuild/3.5/Microsoft.Common.tasks: New. * xbuild/4.0/Microsoft.Common.tasks: New. Use the corresponding 3.5/4.0 tasks assembly. * xbuild_targets.make: Copies the target and tasks file in the correct place, to allow running tests with different toolsversion. * Makefile: Import xbuild_targets.make . Use correct assembly names for Utilities assembly, for 3.5/4.0 profiles. Install the correct Microsoft.Common.tasks file for the profile. Copy xbuild.exe to class/li$(PROFILE), so that it can find other profile dirs as relative path. (EXTRA_DISTFILES): Add the new Microsoft.Common.tasks files. git-svn-id: svn+ssh://mono-cvs.ximian.com/source/trunk/mcs@154835 e3ebcda4-bce8-0310-ba0a-eca2169e7518 --- ChangeLog | 4 + Makefile | 2 +- class/Microsoft.Build.Engine/ChangeLog | 13 ++ class/Microsoft.Build.Engine/Makefile | 42 ++++- .../Microsoft.Build.BuildEngine/BuildEngine.cs | 28 +++- .../Microsoft.Build.BuildEngine/BuildTask.cs | 22 ++- .../Microsoft.Build.BuildEngine/ChangeLog | 22 +++ .../Microsoft.Build.BuildEngine/Engine.cs | 153 +++++++++++++---- .../Microsoft.Build.BuildEngine/LogExtensions.cs | 183 +++++++++++++++++++++ .../Microsoft.Build.BuildEngine/Project.cs | 55 ++++++- .../Microsoft.Build.BuildEngine/Toolset.cs} | 35 ++-- .../ToolsetCollection.cs | 99 +++++++++++ .../ToolsetDefinitionLocations.cs} | 29 ++-- .../Microsoft.Build.Engine.dll.sources | 4 + .../Test/Microsoft.Build.BuildEngine/ChangeLog | 8 + .../Test/Microsoft.Build.BuildEngine/Consts.cs | 24 +++ .../Test/Microsoft.Build.BuildEngine/EngineTest.cs | 111 +++++++------ .../Microsoft.Build.BuildEngine/ProjectTest.cs | 6 +- .../Test/test-config-file-net-3.5 | 15 ++ .../Test/test-config-file-net-4.0 | 15 ++ class/Microsoft.Build.Framework/ChangeLog | 7 + class/Microsoft.Build.Framework/Makefile | 4 + .../Microsoft.Build.Framework.dll.sources | 1 + .../Microsoft.Build.Framework/ChangeLog | 4 + .../Microsoft.Build.Framework/IBuildEngine2.cs} | 39 +++-- class/Microsoft.Build.Tasks/ChangeLog | 11 ++ class/Microsoft.Build.Tasks/Makefile | 32 +++- .../Microsoft.Build.Tasks/ChangeLog | 6 + .../Microsoft.Build.Tasks/Csc.cs | 4 + .../Microsoft.Build.Tasks/MSBuild.cs | 19 ++- .../Microsoft.Build.Tasks_test.dll.sources | 2 +- .../AssignProjectConfigurationTest.cs | 8 +- .../Test/Microsoft.Build.Tasks/ChangeLog | 14 ++ .../CreateCSharpManifestResourceNameTest.cs | 11 +- .../Test/Microsoft.Build.Tasks/CreateItemTest.cs | 4 +- .../CreateVisualBasicManifestResourceNameTest.cs | 11 +- .../Microsoft.Build.Tasks/FindAppConfigFileTest.cs | 6 +- .../Microsoft.Build.Tasks/RemoveDuplicatesTest.cs | 2 +- .../Test/Microsoft.Build.Tasks/TaskBatchingTest.cs | 22 ++- .../Microsoft.Build.Tasks/WriteLinesToFileTest.cs | 2 +- .../Test/test-config-file-net-3.5 | 15 ++ .../Test/test-config-file-net-4.0 | 15 ++ class/Microsoft.Build.Utilities/ChangeLog | 7 + class/Microsoft.Build.Utilities/Makefile | 8 + .../Microsoft.Build.Utilities/ChangeLog | 9 + .../TargetDotNetFrameworkVersion.cs | 5 + .../Microsoft.Build.Utilities/Task.cs | 4 + .../ToolLocationHelper.cs | 23 ++- tools/ChangeLog | 4 + tools/Makefile | 4 +- tools/xbuild/ChangeLog | 24 +++ tools/xbuild/Main.cs | 16 +- tools/xbuild/Makefile | 25 ++- tools/xbuild/Parameters.cs | 10 +- tools/xbuild/SolutionParser.cs | 35 ++++ .../xbuild/xbuild/{ => 2.0}/Microsoft.Common.tasks | 0 tools/xbuild/xbuild/3.5/Microsoft.Common.tasks | 34 ++++ tools/xbuild/xbuild/4.0/Microsoft.Common.tasks | 34 ++++ tools/xbuild/xbuild_targets.make | 21 +++ 59 files changed, 1183 insertions(+), 189 deletions(-) create mode 100644 class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/LogExtensions.cs copy class/{Microsoft.Build.Utilities/Microsoft.Build.Utilities/TargetDotNetFrameworkVersion.cs => Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Toolset.cs} (63%) create mode 100644 class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ToolsetCollection.cs rename class/{Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/Consts.cs => Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ToolsetDefinitionLocations.cs} (70%) create mode 100644 class/Microsoft.Build.Engine/Test/test-config-file-net-3.5 create mode 100644 class/Microsoft.Build.Engine/Test/test-config-file-net-4.0 copy class/{Microsoft.Build.Utilities/Microsoft.Build.Utilities/TargetDotNetFrameworkVersion.cs => Microsoft.Build.Framework/Microsoft.Build.Framework/IBuildEngine2.cs} (54%) create mode 100644 class/Microsoft.Build.Tasks/Test/test-config-file-net-3.5 create mode 100644 class/Microsoft.Build.Tasks/Test/test-config-file-net-4.0 rename tools/xbuild/xbuild/{ => 2.0}/Microsoft.Common.tasks (100%) create mode 100644 tools/xbuild/xbuild/3.5/Microsoft.Common.tasks create mode 100644 tools/xbuild/xbuild/4.0/Microsoft.Common.tasks create mode 100644 tools/xbuild/xbuild_targets.make diff --git a/ChangeLog b/ChangeLog index 401517b94e..3111e81a8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-04-03 Ankit Jain + + * Makefile: Process tools/xbuild for 3.5 also. + 2010-03-16 Jb Evain * Makefile: rename the net_2_1 profile to moonlight. diff --git a/Makefile b/Makefile index 311d477ced..3c04be99c3 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ moonlight_raw_SUBDIRS := build mcs class tools moonlight_SUBDIRS := tools tests errors monotouch_SUBDIRS := build mcs class monotouch_bootstrap_SUBDIRS := build mcs class -net_3_5_SUBDIRS := build class +net_3_5_SUBDIRS := build class tools/xbuild net_4_0_bootstrap_SUBDIRS := build mcs class tools net_4_0_SUBDIRS := build mcs class nunit24 ilasm tools tests errors docs diff --git a/class/Microsoft.Build.Engine/ChangeLog b/class/Microsoft.Build.Engine/ChangeLog index 0052a5560c..0308f07f73 100644 --- a/class/Microsoft.Build.Engine/ChangeLog +++ b/class/Microsoft.Build.Engine/ChangeLog @@ -1,3 +1,16 @@ +2010-04-03 Ankit Jain + + * Makefile: Use the correct assembly name for MS.Build.Utilities* + for 3.5 and 4.0 profiles. Copy the .config files for the test + assembly. + Import tools/xbuild/xbuild_targets.make, which copies the target + and tasks file in the correct place, to allow running tests + with different toolsversion. + * Microsoft.Build.Engine.dll.sources: Add LogExtensions.cs, + Toolset.cs, ToolsetDefinitionLocations.cs and ToolsetCollection.cs . + * Test/test-config-file-net-3.5: New. + * Test/test-config-file-net-4.0: New. + 2010-02-19 Ankit Jain * Microsoft.Build.Engine.dll.sources: Add ProjectLoadSettings.cs . diff --git a/class/Microsoft.Build.Engine/Makefile b/class/Microsoft.Build.Engine/Makefile index d46bf87bf1..343ea6d865 100644 --- a/class/Microsoft.Build.Engine/Makefile +++ b/class/Microsoft.Build.Engine/Makefile @@ -11,23 +11,57 @@ NO_TEST = yes NO_SIGN_ASSEMBLY = yes endif +ifeq (3.5, $(FRAMEWORK_VERSION)) +NAME_SUFFIX = .v3.5 +else +ifeq (4.0, $(FRAMEWORK_VERSION)) +NAME_SUFFIX = .v4.0 +endif +endif + LIB_MCS_FLAGS = \ /r:$(corlib) \ /r:System.dll \ + /r:System.Core.dll \ /r:System.Xml.dll \ /r:Microsoft.Build.Framework.dll \ - /r:Microsoft.Build.Utilities.dll + /r:Microsoft.Build.Utilities$(NAME_SUFFIX).dll TEST_MCS_FLAGS = \ /r:Microsoft.Build.Framework.dll \ - /r:Microsoft.Build.Utilities.dll + /r:Microsoft.Build.Utilities$(NAME_SUFFIX).dll EXTRA_DISTFILES = \ Test/resources/TestTasks.cs \ - Test/resources/*.*proj + Test/resources/*.*proj \ + Test/resources/TestTasks.dll.config \ + Test/test-config-file* Test/resources/TestTasks.dll: Test/resources/TestTasks.cs - $(CSCOMPILE) Test/resources/TestTasks.cs /r:Microsoft.Build.Framework.dll /r:Microsoft.Build.Utilities.dll /target:library + $(CSCOMPILE) Test/resources/TestTasks.cs /r:Microsoft.Build.Framework.dll /r:Microsoft.Build.Utilities$(NAME_SUFFIX).dll /target:library + +clean-local: clean-test-tasks + +clean-test-tasks: + rm -f Test/resources/TestTasks.dll + +test-local: copy-config + +ifeq (net_4_0, $(PROFILE)) +copy-config: + cp Test/test-config-file-net-4.0 $(test_lib).config +else +ifeq (net_3_5, $(PROFILE)) +copy-config: + cp Test/test-config-file-net-3.5 $(test_lib).config +else +copy-config: +endif +endif + +export TESTING_MONO=a +XBUILD_DIR=../../tools/xbuild +include $(XBUILD_DIR)/xbuild_targets.make test-local: Test/resources/TestTasks.dll diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildEngine.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildEngine.cs index 0200f6f2a8..1d48f92250 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildEngine.cs +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildEngine.cs @@ -32,7 +32,7 @@ using System.Collections; using Microsoft.Build.Framework; namespace Microsoft.Build.BuildEngine { - internal class BuildEngine : IBuildEngine { + internal class BuildEngine : IBuildEngine2 { Engine engine; int columnNumberOfTaskNode; @@ -60,7 +60,16 @@ namespace Microsoft.Build.BuildEngine { IDictionary globalProperties, IDictionary targetOutputs) { + return BuildProjectFile (projectFileName, targetNames, globalProperties, targetOutputs, null); + } + + public bool BuildProjectFile (string projectFileName, + string[] targetNames, + IDictionary globalProperties, + IDictionary targetOutputs, string toolsVersion) + { if (String.IsNullOrEmpty (projectFileName)) { + project.ToolsVersion = toolsVersion; return engine.BuildProject (project, targetNames, targetOutputs, BuildSettings.DoNotResetPreviouslyBuiltTargets); } else { @@ -71,10 +80,21 @@ namespace Microsoft.Build.BuildEngine { (string) de.Key, (string) de.Value, PropertyType.Global)); return engine.BuildProjectFile (projectFileName, - targetNames, bpg, targetOutputs, BuildSettings.DoNotResetPreviouslyBuiltTargets); + targetNames, bpg, targetOutputs, BuildSettings.DoNotResetPreviouslyBuiltTargets, toolsVersion); } } + public bool BuildProjectFilesInParallel (string[] projectFileNames, + string [] targetNames, + IDictionary[] globalProperties, + IDictionary[] targetOutputsPerProject, + string[] toolsVersion, + bool useResultsCache, + bool unloadProjectsOnCompletion) + { + throw new NotImplementedException (); + } + // Raises a custom event to all registered loggers. public void LogCustomEvent (CustomBuildEventArgs e) { @@ -128,6 +148,10 @@ namespace Microsoft.Build.BuildEngine { public string ProjectFileOfTaskNode { get { return taskfile; } } + + public bool IsRunningMultipleNodes { + get { return false; } + } } } diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildTask.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildTask.cs index 9edeeb5a82..38bdad84bf 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildTask.cs +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/BuildTask.cs @@ -176,27 +176,31 @@ namespace Microsoft.Build.BuildEngine { void LogError (string message, params object[] messageArgs) { - BuildErrorEventArgs beea = new BuildErrorEventArgs ( - null, null, null, 0, 0, 0, 0, String.Format (message, messageArgs), - null, null); - parentTarget.Project.ParentEngine.EventSource.FireErrorRaised (this, beea); + parentTarget.Project.ParentEngine.LogError (message, messageArgs); } void LogMessage (MessageImportance importance, string message, params object[] messageArgs) { - BuildMessageEventArgs bmea = new BuildMessageEventArgs ( - String.Format (message, messageArgs), null, - null, importance); - parentTarget.Project.ParentEngine.EventSource.FireMessageRaised (this, bmea); + parentTarget.Project.ParentEngine.LogMessage (importance, message, messageArgs); } ITask InitializeTask () { ITask task; - task = (ITask)Activator.CreateInstance (this.Type); + try { + task = (ITask)Activator.CreateInstance (this.Type); + } catch (InvalidCastException) { + LogMessage (MessageImportance.Low, "InvalidCastException, ITask: {0} Task type: {1}", + typeof (ITask).AssemblyQualifiedName, this.Type.AssemblyQualifiedName); + throw; + } + parentTarget.Project.ParentEngine.LogMessage ( + MessageImportance.Low, + "Using task {0} from {1}", Name, this.Type.AssemblyQualifiedName); + task.BuildEngine = new BuildEngine (parentTarget.Project.ParentEngine, parentTarget.Project, parentTarget.TargetFile, 0, 0, ContinueOnError); task_logger = new TaskLoggingHelper (task); diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog index adf15516dd..87a8914b39 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ChangeLog @@ -1,3 +1,25 @@ +2010-04-03 Ankit Jain + + * BuildEngine.cs: Implement IBuildEngine2 instead of + IBuildEngine. + * BuildTasks.cs: Use the new extension methods for logging. + (InitializeTask): Emit a message informing about the assembly + from which the task is being loaded. Emit a useful debug message + incase of a InvalidCastException. + * Engine.cs: Add missing methods, constructors and properties related + to ToolsVersion support. Setup a default set of Toolsets. + Keep separate taskdbs' per ToolsVersion. The common tasks + would come from different *.tasks file, and use different + task assemblies. + (DefaultToolsVersion): Correctly set this based on the profile. + * LogExtensions.cs: New. Extension methods on Engine, for logging. + * Project.cs: Add missing methods/contructors/properties related + to ToolsVersion support. Add reserved properties - + MSBuildToolsPath and MSBuildToolsVersion . + * Toolset.cs: New. + * ToolsetCollection.cs: New. + * ToolsetDefinitionLocations.cs: New. + 2010-03-04 Ankit Jain * BuildEngine.cs (LogErrorEvent): Log as warning, if diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs index a8f6a067a2..caefd7f9db 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs @@ -40,16 +40,17 @@ namespace Microsoft.Build.BuildEngine { string binPath; bool buildEnabled; - TaskDatabase defaultTasks; - bool defaultTasksRegistered; + Dictionary defaultTasksTableByToolsVersion; const string defaultTasksProjectName = "Microsoft.Common.tasks"; EventSource eventSource; bool buildStarted; + ToolsetDefinitionLocations toolsetLocations; BuildPropertyGroup global_properties; //IDictionary importedProjects; List loggers; //bool onlyLogCriticalEvents; Dictionary projects; + string defaultToolsVersion; // the key here represents the project+target+global_properties set Dictionary builtTargetsOutputByName; @@ -68,6 +69,25 @@ namespace Microsoft.Build.BuildEngine { { } + public Engine (ToolsetDefinitionLocations locations) + : this (ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20)) + { + toolsetLocations = locations; + } + + public Engine (BuildPropertyGroup globalProperties) + : this (ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20)) + { + this.global_properties = globalProperties; + } + + public Engine (BuildPropertyGroup globalProperties, ToolsetDefinitionLocations locations) + : this (ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20)) + { + this.global_properties = globalProperties; + toolsetLocations = locations; + } + // engine should be invoked with path where binary files are // to find microsoft.build.tasks public Engine (string binPath) @@ -81,8 +101,25 @@ namespace Microsoft.Build.BuildEngine { this.global_properties = new BuildPropertyGroup (); this.builtTargetsOutputByName = new Dictionary (); this.currentlyBuildingProjectsStack = new Stack (); - - RegisterDefaultTasks (); + this.Toolsets = new ToolsetCollection (); + LoadDefaultToolsets (); + defaultTasksTableByToolsVersion = new Dictionary (); + GetDefaultTasks (DefaultToolsVersion); + } + + //FIXME: should be loaded from config file + void LoadDefaultToolsets () + { + Toolsets.Add (new Toolset ("2.0", + ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20))); + Toolsets.Add (new Toolset ("3.0", + ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version30))); + Toolsets.Add (new Toolset ("3.5", + ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version35))); +#if NET_4_0 + Toolsets.Add (new Toolset ("4.0", + ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version40))); +#endif } [MonoTODO] @@ -128,27 +165,31 @@ namespace Microsoft.Build.BuildEngine { if (targetNames == null) return false; + if (defaultToolsVersion != null) + // it has been explicitly set, xbuild does this.. + project.ToolsVersion = defaultToolsVersion; return project.Build (targetNames, targetOutputs, buildFlags); } [MonoTODO] public bool BuildProjectFile (string projectFile) { - throw new NotImplementedException (); + return BuildProjectFile (projectFile, new string [0]); } [MonoTODO] public bool BuildProjectFile (string projectFile, string targetName) { - throw new NotImplementedException (); + return BuildProjectFile (projectFile, + targetName == null ? new string [0] : new string [] {targetName}); } [MonoTODO] public bool BuildProjectFile (string projectFile, string[] targetNames) { - throw new NotImplementedException (); + return BuildProjectFile (projectFile, targetNames, null); } [MonoTODO] @@ -174,6 +215,16 @@ namespace Microsoft.Build.BuildEngine { IDictionary targetOutputs, BuildSettings buildFlags) { + return BuildProjectFile (projectFile, targetNames, globalProperties, targetOutputs, buildFlags, null); + } + + //FIXME: add a test for null @toolsVersion + public bool BuildProjectFile (string projectFile, + string[] targetNames, + BuildPropertyGroup globalProperties, + IDictionary targetOutputs, + BuildSettings buildFlags, string toolsVersion) + { Project project; if (projects.ContainsKey (projectFile)) { @@ -197,6 +248,13 @@ namespace Microsoft.Build.BuildEngine { } try { + if (String.IsNullOrEmpty (toolsVersion) && defaultToolsVersion != null) + // it has been explicitly set, xbuild does this.. + //FIXME: should this be cleared after building? + project.ToolsVersion = defaultToolsVersion; + else + project.ToolsVersion = toolsVersion; + return project.Build (targetNames, targetOutputs, buildFlags); } finally { if (globalProperties != null) { @@ -217,8 +275,6 @@ namespace Microsoft.Build.BuildEngine { public Project CreateNewProject () { - if (defaultTasksRegistered) - CheckBinPath (); return new Project (this); } @@ -358,23 +414,44 @@ namespace Microsoft.Build.BuildEngine { bfea = new BuildFinishedEventArgs ("Build finished.", null, succeeded); eventSource.FireBuildFinished (this, bfea); } + + internal TaskDatabase GetDefaultTasks (string toolsVersion) + { + TaskDatabase db; + if (defaultTasksTableByToolsVersion.TryGetValue (toolsVersion, out db)) + return db; + + var toolset = Toolsets [toolsVersion]; + if (toolset == null) + throw new Exception ("Unknown toolsversion: " + toolsVersion); + + string toolsPath = toolset.ToolsPath; + string tasksFile = Path.Combine (toolsPath, defaultTasksProjectName); + this.LogMessage (MessageImportance.Low, "Loading default tasks for ToolsVersion: {0} from {1}", toolsVersion, tasksFile); + + // set a empty taskdb here, because the project loading the tasks + // file will try to get the default task db + defaultTasksTableByToolsVersion [toolsVersion] = new TaskDatabase (); + + db = defaultTasksTableByToolsVersion [toolsVersion] = RegisterDefaultTasks (tasksFile); + + return db; + } - void RegisterDefaultTasks () + TaskDatabase RegisterDefaultTasks (string tasksFile) { - this.defaultTasksRegistered = false; - Project defaultTasksProject = CreateNewProject (); + TaskDatabase db; - if (binPath != null) { - if (File.Exists (Path.Combine (binPath, defaultTasksProjectName))) { - defaultTasksProject.Load (Path.Combine (binPath, defaultTasksProjectName)); - defaultTasks = defaultTasksProject.TaskDatabase; - } else - defaultTasks = new TaskDatabase (); - } else - defaultTasks = new TaskDatabase (); - - this.defaultTasksRegistered = true; + if (File.Exists (tasksFile)) { + defaultTasksProject.Load (tasksFile); + db = defaultTasksProject.TaskDatabase; + } else { + this.LogWarning ("Default tasks file {0} not found, ignoring.", tasksFile); + db = new TaskDatabase (); + } + + return db; } public string BinPath { @@ -403,7 +480,31 @@ namespace Microsoft.Build.BuildEngine { get { return global_properties; } set { global_properties = value; } } + + public ToolsetCollection Toolsets { + get; private set; + } + public string DefaultToolsVersion { + get { + if (String.IsNullOrEmpty (defaultToolsVersion)) +#if NET_4_0 + return "4.0"; +#elif NET_3_5 + return "3.5"; +#else + return "2.0"; +#endif + + return defaultToolsVersion; + } + set { defaultToolsVersion = value; } + } + + public bool IsBuilding { + get { return buildStarted; } + } + public bool OnlyLogCriticalEvents { get { return eventSource.OnlyLogCriticalEvents; } set { eventSource.OnlyLogCriticalEvents = value; } @@ -413,14 +514,6 @@ namespace Microsoft.Build.BuildEngine { get { return eventSource; } } - internal bool DefaultTasksRegistered { - get { return defaultTasksRegistered; } - } - - internal TaskDatabase DefaultTasks { - get { return defaultTasks; } - } - internal Dictionary BuiltTargetsOutputByName { get { return builtTargetsOutputByName; } } diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/LogExtensions.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/LogExtensions.cs new file mode 100644 index 0000000000..030ea8aa86 --- /dev/null +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/LogExtensions.cs @@ -0,0 +1,183 @@ +// +// LogExtensions.cs: Extension methods for logging on Engine +// +// Author: +// Ankit Jain (jankit@novell.com) +// +// Copyright 2010 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +#if NET_2_0 + +using System; +using System.IO; +using System.Text; +using Microsoft.Build.Framework; + +namespace Microsoft.Build.BuildEngine +{ + static class LogExtensions + { + public static string FormatString (string unformatted, + params object[] args) + { + if (unformatted == null) + throw new ArgumentNullException ("unformatted"); + + if (args == null || args.Length == 0) + return unformatted; + else + return String.Format (unformatted, args); + } + + public static void LogError (this Engine engine, string message, + params object[] messageArgs) + { + if (message == null) + throw new ArgumentNullException ("message"); + + BuildErrorEventArgs beea = new BuildErrorEventArgs ( + null, null, null, 0, 0, 0, 0, FormatString (message, messageArgs), + null, null); + engine.EventSource.FireErrorRaised (engine, beea); + } + + public static void LogError (this Engine engine, string subcategory, string errorCode, + string helpKeyword, string file, + int lineNumber, int columnNumber, + int endLineNumber, int endColumnNumber, + string message, + params object[] messageArgs) + { + if (message == null) + throw new ArgumentNullException ("message"); + + BuildErrorEventArgs beea = new BuildErrorEventArgs ( + subcategory, errorCode, file, lineNumber, + columnNumber, endLineNumber, endColumnNumber, + FormatString (message, messageArgs), helpKeyword /*it's helpKeyword*/, + null /*it's senderName*/); + + engine.EventSource.FireErrorRaised (engine, beea); + } + + public static void LogErrorFromException (this Engine engine, Exception e) + { + LogErrorFromException (engine, e, true); + } + + public static void LogErrorFromException (this Engine engine, Exception e, + bool showStackTrace) + { + LogErrorFromException (engine, e, showStackTrace, true, String.Empty); + } + + [MonoTODO ("Arguments @showDetail and @file are not honored")] + public static void LogErrorFromException (this Engine engine, Exception e, + bool showStackTrace, bool showDetail, string file) + { + if (e == null) + throw new ArgumentNullException ("e"); + + StringBuilder sb = new StringBuilder (); + sb.Append (e.Message); + if (showStackTrace == true) + sb.Append (e.StackTrace); + BuildErrorEventArgs beea = new BuildErrorEventArgs ( + null, null, null, 0, 0, 0, 0, sb.ToString (), + e.HelpLink, e.Source); + engine.EventSource.FireErrorRaised (engine, beea); + } + + public static void LogMessage (this Engine engine, string message, + params object[] messageArgs) + { + LogMessage (engine, MessageImportance.Normal, message, messageArgs); + } + + public static void LogMessage (this Engine engine, MessageImportance importance, + string message, + params object[] messageArgs) + { + if (message == null) + throw new ArgumentNullException ("message"); + + LogMessageFromText (engine, FormatString (message, messageArgs), importance); + } + + public static bool LogMessageFromText (this Engine engine, string lineOfText, + MessageImportance importance) + { + if (lineOfText == null) + throw new ArgumentNullException ("lineOfText"); + + BuildMessageEventArgs bmea = new BuildMessageEventArgs ( + lineOfText, null, + null, importance); + + engine.EventSource.FireMessageRaised (engine, bmea); + + return true; + } + + public static void LogWarning (this Engine engine, string message, + params object[] messageArgs) + { + // FIXME: what about all the parameters? + BuildWarningEventArgs bwea = new BuildWarningEventArgs ( + null, null, null, 0, 0, 0, 0, FormatString (message, messageArgs), + null, null); + engine.EventSource.FireWarningRaised (engine, bwea); + } + + public static void LogWarning (this Engine engine, string subcategory, string warningCode, + string helpKeyword, string file, + int lineNumber, int columnNumber, + int endLineNumber, int endColumnNumber, + string message, + params object[] messageArgs) + { + BuildWarningEventArgs bwea = new BuildWarningEventArgs ( + subcategory, warningCode, file, lineNumber, + columnNumber, endLineNumber, endColumnNumber, + FormatString (message, messageArgs), helpKeyword, null); + engine.EventSource.FireWarningRaised (engine, bwea); + } + + public static void LogWarningFromException (this Engine engine, Exception e) + { + LogWarningFromException (engine, e, false); + } + + public static void LogWarningFromException (this Engine engine, Exception e, + bool showStackTrace) + { + StringBuilder sb = new StringBuilder (); + sb.Append (e.Message); + if (showStackTrace) + sb.Append (e.StackTrace); + LogWarning (engine, null, null, null, null, 0, 0, 0, 0, + sb.ToString (), null); + } + } +} + +#endif diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs index b5b0b1aa81..a103b762a1 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Project.cs @@ -89,9 +89,14 @@ namespace Microsoft.Build.BuildEngine { { } - public Project (Engine engine) + public Project (Engine engine) : this (engine, null) + { + } + + public Project (Engine engine, string toolsVersion) { parentEngine = engine; + ToolsVersion = toolsVersion; buildEnabled = ParentEngine.BuildEnabled; xmlDocument = new XmlDocument (); @@ -116,6 +121,7 @@ namespace Microsoft.Build.BuildEngine { GlobalProperties.AddProperty (bp.Clone (true)); ProcessXml (); + } [MonoTODO ("Not tested")] @@ -793,8 +799,7 @@ namespace Microsoft.Build.BuildEngine { last_item_group_containing = new Dictionary (); taskDatabase = new TaskDatabase (); - if (ParentEngine.DefaultTasksRegistered) - taskDatabase.CopyTasks (ParentEngine.DefaultTasks); + taskDatabase.CopyTasks (ParentEngine.GetDefaultTasks (GetToolsVersionToUse ())); initialTargets = new List (); defaultTargets = new string [0]; @@ -860,7 +865,7 @@ namespace Microsoft.Build.BuildEngine { AddChoose (xe); break; default: - throw new InvalidProjectFileException ("Invalid element in project file."); + throw new InvalidProjectFileException (String.Format ("Invalid element '{0}' in project file.", xe.Name)); } } } @@ -928,7 +933,12 @@ namespace Microsoft.Build.BuildEngine { Path.GetFileNameWithoutExtension (fullFileName), PropertyType.Reserved)); EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildBinPath", parentEngine.BinPath, PropertyType.Reserved)); - EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildToolsPath", parentEngine.BinPath, PropertyType.Reserved)); + string toolsVersionToUse = GetToolsVersionToUse (); + string toolsPath = parentEngine.Toolsets [toolsVersionToUse].ToolsPath; + if (toolsPath == null) + throw new Exception ("Unknown toolsVersion: " + toolsVersionToUse); + EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildToolsPath", toolsPath, PropertyType.Reserved)); + EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildToolsVersion", toolsVersionToUse, PropertyType.Reserved)); EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildExtensionsPath", ExtensionsPath, PropertyType.Reserved)); EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildProjectDefaultTargets", DefaultTargets, PropertyType.Reserved)); EvaluatedProperties.AddProperty (new BuildProperty ("OS", OS, PropertyType.Environment)); @@ -942,6 +952,18 @@ namespace Microsoft.Build.BuildEngine { EvaluatedProperties.AddProperty (new BuildProperty ("MSBuildProjectDirectory", projectDir, PropertyType.Reserved)); } + + string GetToolsVersionToUse () + { + if (String.IsNullOrEmpty (ToolsVersion)) { + if (HasToolsVersionAttribute) + return DefaultToolsVersion; + else + return parentEngine.DefaultToolsVersion; + } else { + return ToolsVersion; + } + } void AddProjectExtensions (XmlElement xmlElement) { @@ -1316,6 +1338,29 @@ namespace Microsoft.Build.BuildEngine { get { return xmlDocument.InnerXml; } } + // corresponds to the xml attribute + public string DefaultToolsVersion { + get { + if (xmlDocument != null) + return xmlDocument.DocumentElement.GetAttribute ("ToolsVersion"); + return null; + } + set { + if (xmlDocument != null) + xmlDocument.DocumentElement.SetAttribute ("ToolsVersion", value); + } + } + + public bool HasToolsVersionAttribute { + get { + return xmlDocument != null && xmlDocument.DocumentElement.HasAttribute ("ToolsVersion"); + } + } + + public string ToolsVersion { + get; internal set; + } + internal List BuiltTargetKeys { get { return builtTargetKeys; } } diff --git a/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/TargetDotNetFrameworkVersion.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Toolset.cs similarity index 63% copy from class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/TargetDotNetFrameworkVersion.cs copy to class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Toolset.cs index 451e40ef14..d7955176a4 100644 --- a/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/TargetDotNetFrameworkVersion.cs +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Toolset.cs @@ -1,10 +1,10 @@ // -// TargetDotNetFrameworkVersion.cs: Represents framework version. +// Toolset.cs // // Author: -// Marek Sieradzki (marek.sieradzki@gmail.com) +// Ankit Jain (jankit@novell.com) // -// (C) 2005 Marek Sieradzki +// Copyright 2010 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -26,19 +26,28 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #if NET_2_0 +using System; -namespace Microsoft.Build.Utilities +namespace Microsoft.Build.BuildEngine { - // If changing something here then update - // ToolLocationHelper.GetPathToDotNetFramework also - public enum TargetDotNetFrameworkVersion + public class Toolset { - Version11, - Version20, - Version30, - Version35, - VersionLatest = Version35 + public Toolset (string toolsVersion, string toolsPath, BuildPropertyGroup buildProperties) + { + ToolsVersion = toolsVersion; + ToolsPath = toolsPath; + BuildProperties = buildProperties; + } + + public Toolset (string toolsVersion, string toolsPath) + : this (toolsVersion, toolsPath, null) + { + } + + public BuildPropertyGroup BuildProperties { get; private set; } + + public string ToolsVersion { get; private set; } + public string ToolsPath { get; private set; } } } - #endif diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ToolsetCollection.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ToolsetCollection.cs new file mode 100644 index 0000000000..0c332d45d5 --- /dev/null +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ToolsetCollection.cs @@ -0,0 +1,99 @@ +// +// ToolsetCollection.cs +// +// Author: +// Ankit Jain (jankit@novell.com) +// +// Copyright 2010 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +#if NET_2_0 + +using System; +using System.Collections.Generic; +using System.Collections; + +namespace Microsoft.Build.BuildEngine +{ + + public class ToolsetCollection : ICollection, IEnumerable, IEnumerable + { + List toolsets; + + internal ToolsetCollection () + { + toolsets = new List (); + } + + public int Count + { + get { return toolsets.Count; } + } + + public bool IsReadOnly { get { return false; } } + + public Toolset this [string toolsVersion] + { + get { return toolsets.Find (item => item.ToolsVersion == toolsVersion); } + } + + public void Add (Toolset item) + { + toolsets.Add (item); + } + + public void Clear () + { + toolsets.Clear (); + } + + public bool Contains (string toolsVersion) + { + return toolsets.Exists (item => item.ToolsVersion == toolsVersion); + } + + public bool Contains (Toolset item) + { + return toolsets.Contains (item); + } + + public void CopyTo (Toolset[] array, int arrayIndex) + { + toolsets.CopyTo (array, arrayIndex); + } + + public IEnumerator GetEnumerator () + { + return toolsets.GetEnumerator (); + } + + IEnumerator IEnumerable.GetEnumerator () + { + return toolsets.GetEnumerator (); + } + + public bool Remove (Toolset item) + { + return toolsets.Remove (item); + } + } +} +#endif diff --git a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/Consts.cs b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ToolsetDefinitionLocations.cs similarity index 70% rename from class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/Consts.cs rename to class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ToolsetDefinitionLocations.cs index 2f41a67c3d..6f5e106b8e 100644 --- a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/Consts.cs +++ b/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/ToolsetDefinitionLocations.cs @@ -1,10 +1,10 @@ // -// Consts.cs +// ToolsetDefinitionLocations.cs // // Author: -// Marek Sieradzki (marek.sieradzki@gmail.com) +// Ankit Jain (jankit@novell.com) // -// (C) 2006 Marek Sieradzki +// Copyright 2010 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -25,22 +25,15 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -using System; -using Microsoft.Build.Utilities; +#if NET_2_0 -public static class Consts { - - static bool RunningOnMono () +namespace Microsoft.Build.BuildEngine +{ + public enum ToolsetDefinitionLocations { - return Type.GetType ("Mono.Runtime") != null; - } - - public static string BinPath { - get { - if (RunningOnMono ()) - return "../../tools/xbuild/xbuild"; - else - return ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20); - } + None, + ConfigurationFile, + Registry } } +#endif diff --git a/class/Microsoft.Build.Engine/Microsoft.Build.Engine.dll.sources b/class/Microsoft.Build.Engine/Microsoft.Build.Engine.dll.sources index 8f429b31a7..02bc4c2002 100644 --- a/class/Microsoft.Build.Engine/Microsoft.Build.Engine.dll.sources +++ b/class/Microsoft.Build.Engine/Microsoft.Build.Engine.dll.sources @@ -46,6 +46,7 @@ Microsoft.Build.BuildEngine/InternalLoggerException.cs Microsoft.Build.BuildEngine/InvalidProjectFileException.cs Microsoft.Build.BuildEngine/IReference.cs Microsoft.Build.BuildEngine/ItemReference.cs +Microsoft.Build.BuildEngine/LogExtensions.cs Microsoft.Build.BuildEngine/MetadataReference.cs Microsoft.Build.BuildEngine/Project.cs Microsoft.Build.BuildEngine/ProjectLoadSettings.cs @@ -56,6 +57,9 @@ Microsoft.Build.BuildEngine/Target.cs Microsoft.Build.BuildEngine/TaskDatabase.cs Microsoft.Build.BuildEngine/TaskEngine.cs Microsoft.Build.BuildEngine/Token.cs +Microsoft.Build.BuildEngine/Toolset.cs +Microsoft.Build.BuildEngine/ToolsetCollection.cs +Microsoft.Build.BuildEngine/ToolsetDefinitionLocations.cs Microsoft.Build.BuildEngine/UsingTask.cs Microsoft.Build.BuildEngine/UsingTaskCollection.cs Microsoft.Build.BuildEngine/Utilities.cs diff --git a/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ChangeLog b/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ChangeLog index 7a11426c77..c6084a139c 100644 --- a/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ChangeLog +++ b/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ChangeLog @@ -1,3 +1,11 @@ +2010-04-06 Ankit Jain + + * Consts.cs (ToolsVersionString): New. + (GetTasksAsmPath): New. + * EngineTest.cs: Use the direct path to the tasks assembly + in the UsingTasks. + * ProjectTest.cs: Set ToolsVersion to the current profile. + 2010-02-19 Ankit Jain * ImportTest.cs (TestMissingImport*): Add new tests for missing diff --git a/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/Consts.cs b/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/Consts.cs index bae9a32d6e..31a160850a 100644 --- a/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/Consts.cs +++ b/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/Consts.cs @@ -26,6 +26,7 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. using System; +using System.IO; using Microsoft.Build.Utilities; public static class Consts { @@ -43,4 +44,27 @@ public static class Consts { return ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20); } } + + public static string ToolsVersionString { + get { +#if NET_4_0 + return " ToolsVersion='4.0'"; +#elif NET_3_5 + return " ToolsVersion='3.5'"; +#else + return String.Empty; +#endif + } + } + + public static string GetTasksAsmPath () + { +#if NET_4_0 + return Path.Combine (ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version40), "Microsoft.Build.Tasks.v4.0.dll"); +#elif NET_3_5 + return Path.Combine (ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version35), "Microsoft.Build.Tasks.v3.5.dll"); +#else + return Path.Combine (ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20), "Microsoft.Build.Tasks.dll"); +#endif + } } diff --git a/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/EngineTest.cs b/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/EngineTest.cs index e18e464cb9..b64c1f5bcf 100644 --- a/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/EngineTest.cs +++ b/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/EngineTest.cs @@ -324,8 +324,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { [Test] public void TestGlobalProperties1 () { - string mainProject = @" - + string mainProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -333,9 +334,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { "; - string firstProject = @" - + string firstProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -363,8 +364,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { public void TestGlobalProperties1a () { Directory.CreateDirectory ("Test/resources/foo"); - string mainProject = @" - + string mainProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -372,9 +374,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { "; - string firstProject = @" - + string firstProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -401,8 +403,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { [Test] public void TestGlobalProperties1b () { - string mainProject = @" - + string mainProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -410,9 +413,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { "; - string firstProject = @" - + string firstProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -439,8 +442,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { [Test] public void TestGlobalProperties2 () { - string mainProject = @" - + string mainProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -449,9 +453,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { "; - string firstProject = @" - + string firstProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -478,8 +482,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { [Test] public void TestGlobalProperties3 () { - string mainProject = @" - + string mainProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -491,9 +496,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { "; - string firstProject = @" - + string firstProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -521,8 +526,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { [Test] public void TestGlobalProperties4 () { - string mainProject = @" - + string mainProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -534,9 +540,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { "; - string firstProject = @" - + string firstProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -568,8 +574,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { [Test] public void TestGlobalProperties4a () { - string mainProject = @" - + string mainProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -581,9 +588,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { "; - string firstProject = @" - + string firstProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -615,8 +622,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { [Test] public void TestGlobalProperties4b () { - string mainProject = @" - + string mainProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -628,9 +636,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { "; - string firstProject = @" - + string firstProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -666,8 +674,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { [Test] public void TestGlobalProperties4c () { - string mainProject = @" - + string mainProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -679,9 +688,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { "; - string firstProject = @" - + string firstProject = @"" + + GetUsingTask ("MSBuild") + + @" @@ -714,10 +723,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { [Test] public void TestMSBuildOutputs () { - string mainProject = @" - - + string mainProject = @"" + + GetUsingTask ("MSBuild") + + @" value @@ -889,6 +897,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine { } } - + public static string GetUsingTask (string taskName) + { + return ""; + } } } diff --git a/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ProjectTest.cs b/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ProjectTest.cs index cce13c6af6..5d92a43f5a 100644 --- a/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ProjectTest.cs +++ b/class/Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/ProjectTest.cs @@ -1779,7 +1779,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine { Engine engine = new Engine (Consts.BinPath); Project project = engine.CreateNewProject (); - string second = @" + string second = @" InitialVal @@ -1797,7 +1797,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine { sw.Write (second); } - string third = @" + string third = @" Third Value @@ -1972,7 +1972,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine { [Test] public void TestCaseSensitivityOfProjectElements () { - string projectXml = @" + string projectXml = @" md1 diff --git a/class/Microsoft.Build.Engine/Test/test-config-file-net-3.5 b/class/Microsoft.Build.Engine/Test/test-config-file-net-3.5 new file mode 100644 index 0000000000..7756bca8df --- /dev/null +++ b/class/Microsoft.Build.Engine/Test/test-config-file-net-3.5 @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/class/Microsoft.Build.Engine/Test/test-config-file-net-4.0 b/class/Microsoft.Build.Engine/Test/test-config-file-net-4.0 new file mode 100644 index 0000000000..3c78f3b4ec --- /dev/null +++ b/class/Microsoft.Build.Engine/Test/test-config-file-net-4.0 @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/class/Microsoft.Build.Framework/ChangeLog b/class/Microsoft.Build.Framework/ChangeLog index 74073fb065..dea06412ca 100644 --- a/class/Microsoft.Build.Framework/ChangeLog +++ b/class/Microsoft.Build.Framework/ChangeLog @@ -1,3 +1,10 @@ +2010-04-03 Ankit Jain + + * Makefile: Import tools/xbuild/xbuild_targets.make, which copies + the target and tasks file in the correct place, to allow running + tests with different toolsversion. + * Microsoft.Build.Framework.dll.sources: Add IBuildEngine2.cs . + 2006-04-19 Marek Sieradzki * Microsoft.Build.Framework.targets: Removed. diff --git a/class/Microsoft.Build.Framework/Makefile b/class/Microsoft.Build.Framework/Makefile index 74043402bb..0cb68bfac6 100644 --- a/class/Microsoft.Build.Framework/Makefile +++ b/class/Microsoft.Build.Framework/Makefile @@ -17,5 +17,9 @@ LIB_MCS_FLAGS = \ include ../../build/library.make +export TESTING_MONO=a +XBUILD_DIR=../../tools/xbuild +include $(XBUILD_DIR)/xbuild_targets.make + EXTRA_DISTFILES = \ Mono.XBuild.Framework/AssemblyLoadInfo.cs diff --git a/class/Microsoft.Build.Framework/Microsoft.Build.Framework.dll.sources b/class/Microsoft.Build.Framework/Microsoft.Build.Framework.dll.sources index 5be4904c10..7e7d3a57db 100644 --- a/class/Microsoft.Build.Framework/Microsoft.Build.Framework.dll.sources +++ b/class/Microsoft.Build.Framework/Microsoft.Build.Framework.dll.sources @@ -20,6 +20,7 @@ Microsoft.Build.Framework/CustomBuildEventHandler.cs Microsoft.Build.Framework/ExternalProjectFinishedEventArgs.cs Microsoft.Build.Framework/ExternalProjectStartedEventArgs.cs Microsoft.Build.Framework/IBuildEngine.cs +Microsoft.Build.Framework/IBuildEngine2.cs Microsoft.Build.Framework/IEventSource.cs Microsoft.Build.Framework/ILogger.cs Microsoft.Build.Framework/ITask.cs diff --git a/class/Microsoft.Build.Framework/Microsoft.Build.Framework/ChangeLog b/class/Microsoft.Build.Framework/Microsoft.Build.Framework/ChangeLog index 47cfed8525..0f14e7b142 100644 --- a/class/Microsoft.Build.Framework/Microsoft.Build.Framework/ChangeLog +++ b/class/Microsoft.Build.Framework/Microsoft.Build.Framework/ChangeLog @@ -1,3 +1,7 @@ +2010-04-03 Ankit Jain + + * IBuildEngine2.cs: New. + 2006-12-19 Marek Sieradzki * LoggerException.cs: Changed serialization names. diff --git a/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/TargetDotNetFrameworkVersion.cs b/class/Microsoft.Build.Framework/Microsoft.Build.Framework/IBuildEngine2.cs similarity index 54% copy from class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/TargetDotNetFrameworkVersion.cs copy to class/Microsoft.Build.Framework/Microsoft.Build.Framework/IBuildEngine2.cs index 451e40ef14..42b456c3a0 100644 --- a/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/TargetDotNetFrameworkVersion.cs +++ b/class/Microsoft.Build.Framework/Microsoft.Build.Framework/IBuildEngine2.cs @@ -1,10 +1,11 @@ // -// TargetDotNetFrameworkVersion.cs: Represents framework version. +// IBuildEngine2.cs: Provides a way for task authors to use the functionality +// of the MSBuild engine. // // Author: -// Marek Sieradzki (marek.sieradzki@gmail.com) +// Ankit Jain (jankit@novell.com) // -// (C) 2005 Marek Sieradzki +// Copyright 2010 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -27,17 +28,31 @@ #if NET_2_0 -namespace Microsoft.Build.Utilities +using System; +using System.Collections; + +namespace Microsoft.Build.Framework { - // If changing something here then update - // ToolLocationHelper.GetPathToDotNetFramework also - public enum TargetDotNetFrameworkVersion + public interface IBuildEngine2 : IBuildEngine { - Version11, - Version20, - Version30, - Version35, - VersionLatest = Version35 + // Initiates a build of a project file. If the build is + // successful, the outputs (if any) of the specified targets + // are returned. + bool BuildProjectFile (string projectFileName, + string[] targetNames, + IDictionary globalProperties, + IDictionary targetOutputs, string toolsVersion); + + bool BuildProjectFilesInParallel (string[] projectFileNames, + string [] targetNames, + IDictionary[] globalProperties, + IDictionary[] targetOutputsPerProject, + string[] toolsVersion, + bool useResultsCache, + bool unloadProjectsOnCompletion); + + bool IsRunningMultipleNodes { get; } + } } diff --git a/class/Microsoft.Build.Tasks/ChangeLog b/class/Microsoft.Build.Tasks/ChangeLog index 7e8c05ac91..ff531ad013 100644 --- a/class/Microsoft.Build.Tasks/ChangeLog +++ b/class/Microsoft.Build.Tasks/ChangeLog @@ -1,3 +1,14 @@ +2010-04-03 Ankit Jain + + * Makefile: Import tools/xbuild/xbuild_targets.make, which copies + the target and tasks file in the correct place, to allow running + tests with different toolsversion. Copy the config file for the + test assembly. Clean the generated test.dll . + Use the correct target assembly name for 4.0 profile + (ms.build.tasks.v4.0.dll), and for Utilities assembly. + * Microsoft.Build.Tasks_test.dll.sources: Use Consts.cs from Engine + instead of maintaining a copy here. + 2010-03-02 Ankit Jain Fix tests. diff --git a/class/Microsoft.Build.Tasks/Makefile b/class/Microsoft.Build.Tasks/Makefile index 70d2cb6775..34a542a1e1 100644 --- a/class/Microsoft.Build.Tasks/Makefile +++ b/class/Microsoft.Build.Tasks/Makefile @@ -14,6 +14,10 @@ else ifeq (3.5, $(FRAMEWORK_VERSION)) NAME_SUFFIX = .v3.5 +else +ifeq (4.0, $(FRAMEWORK_VERSION)) +NAME_SUFFIX = .v4.0 +endif endif LIBRARY_NAME = Microsoft.Build.Tasks$(NAME_SUFFIX).dll @@ -26,7 +30,7 @@ LIB_MCS_FLAGS = \ /r:System.Core.dll \ /r:System.Xml.dll \ /r:System.Windows.Forms.dll \ - /r:Microsoft.Build.Utilities.dll \ + /r:Microsoft.Build.Utilities$(NAME_SUFFIX).dll \ /r:Microsoft.Build.Framework.dll \ /r:Microsoft.Build.Engine.dll @@ -39,11 +43,35 @@ EXTRA_DISTFILES = \ Test/resources/test.cs \ Test/resources/Sample.cs \ Test/resources/Sample.vb \ - Test/resources/junk.txt + Test/resources/junk.txt \ + Test/test-config-file* test-local: Test/resources/test.dll Test/resources/test.dll: Test/resources/test.cs $(CSCOMPILE) -target:library Test/resources/test.cs +clean-local: clean-test-dll + +clean-test-dll: + rm -f Test/resources/test.dll + +test-local: copy-config + +ifeq (net_4_0, $(PROFILE)) +copy-config: + cp Test/test-config-file-net-4.0 $(test_lib).config +else +ifeq (net_3_5, $(PROFILE)) +copy-config: + cp Test/test-config-file-net-3.5 $(test_lib).config +else +copy-config: +endif +endif + +export TESTING_MONO=a +XBUILD_DIR=../../tools/xbuild +include $(XBUILD_DIR)/xbuild_targets.make + include ../../build/library.make diff --git a/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ChangeLog b/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ChangeLog index 3104cf5673..8fc6eb5d9a 100644 --- a/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ChangeLog +++ b/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ChangeLog @@ -1,3 +1,9 @@ +2010-04-03 Ankit Jain + + * Csc.cs: Use dmcs as the compiler for 4.0 profile. + * MSBuild.cs (ToolsVersion): New. + Use toolsVersion for building. + 2010-02-10 Ankit Jain * GenerateResource.cs (CompileResourceFile): Check File.Exists diff --git a/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Csc.cs b/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Csc.cs index 8b4217ab32..9839966327 100644 --- a/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Csc.cs +++ b/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/Csc.cs @@ -187,7 +187,11 @@ namespace Microsoft.Build.Tasks { protected override string ToolName { get { +#if NET_4_0 + return Utilities.RunningOnWindows ? "dmcs.bat" : "dmcs"; +#else return Utilities.RunningOnWindows ? "gmcs.bat" : "gmcs"; +#endif } } diff --git a/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/MSBuild.cs b/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/MSBuild.cs index 592a412212..564bbb2830 100644 --- a/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/MSBuild.cs +++ b/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/MSBuild.cs @@ -82,7 +82,14 @@ namespace Microsoft.Build.Tasks { outputs = new Hashtable (); try { - result = BuildEngine.BuildProjectFile (filename, targets, global_properties, outputs); + // Order of precedence: + // %(Project.ToolsVersion) , ToolsVersion property + string tv = project.GetMetadata ("ToolsVersion"); + if (String.IsNullOrEmpty (tv)) + tv = ToolsVersion; + ThrowIfNotValidToolsVersion (tv); + + result = BuildEngine2.BuildProjectFile (filename, targets, global_properties, outputs, tv); } catch (InvalidProjectFileException e) { Log.LogError ("Error building project {0}: {1}", filename, e.Message); result = false; @@ -127,6 +134,12 @@ namespace Microsoft.Build.Tasks { return result; } + void ThrowIfNotValidToolsVersion (string toolsVersion) + { + if (!String.IsNullOrEmpty (toolsVersion) && Engine.GlobalEngine.Toolsets [toolsVersion] == null) + throw new Exception (String.Format ("Unknown ToolsVersion : {0}", toolsVersion)); + } + [Required] public ITaskItem [] Projects { get { return projects; } @@ -170,6 +183,10 @@ namespace Microsoft.Build.Tasks { set { buildInParallel = value; } } + public string ToolsVersion { + get; set; + } + Dictionary SplitPropertiesToDictionary () { if (properties == null) diff --git a/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks_test.dll.sources b/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks_test.dll.sources index 4cbc3917c3..0b678d1795 100644 --- a/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks_test.dll.sources +++ b/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks_test.dll.sources @@ -4,7 +4,7 @@ Microsoft.Build.Tasks/AssignProjectConfigurationTest.cs Microsoft.Build.Tasks/AssignTargetPathTest.cs Microsoft.Build.Tasks/CombinePathTest.cs Microsoft.Build.Tasks/CopyTest.cs -Microsoft.Build.Tasks/Consts.cs +../../Microsoft.Build.Engine/Test/Microsoft.Build.BuildEngine/Consts.cs Microsoft.Build.Tasks/CreateCSharpManifestResourceNameTest.cs Microsoft.Build.Tasks/CreateVisualBasicManifestResourceNameTest.cs Microsoft.Build.Tasks/CreateItemTest.cs diff --git a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/AssignProjectConfigurationTest.cs b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/AssignProjectConfigurationTest.cs index 1458c999c6..3673526ed7 100644 --- a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/AssignProjectConfigurationTest.cs +++ b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/AssignProjectConfigurationTest.cs @@ -136,7 +136,7 @@ namespace MonoTests.Microsoft.Build.Tasks { StringBuilder sb = new StringBuilder (); sb.Append (@""); - sb.Append ("\n\n"); + sb.Append ("\n" + GetUsingTask ("AssignProjectConfiguration")); sb.AppendFormat (@"{0}", CreateSolutionConfigurationProperty (guids, "Release|AnyCPU")); sb.Append (CreateProjectReferencesItemGroup (project_ref_guids)); @@ -179,5 +179,11 @@ namespace MonoTests.Microsoft.Build.Tasks sb.Append ("\n"); return sb.ToString (); } + + string GetUsingTask (string taskName) + { + return ""; + } + } } diff --git a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/ChangeLog b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/ChangeLog index 8ce07f826a..73c326e93e 100644 --- a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/ChangeLog +++ b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/ChangeLog @@ -1,3 +1,17 @@ +2010-04-06 Ankit Jain + + * Consts.cs: Remove. + * AssignProjectConfigurationTest.cs: + * CreateCSharpManifestResourceNameTest.cs: + * CreateVisualBasicManifestResourceNameTest.cs: + * CreateItemTest.cs: + * FindAppConfigFileTest.cs: + * RemoveDuplicatesTest.cs: + * TaskBatchingTest.cs: + * WriteLinesToFileTest.cs: + Set the ToolsVersion to match the profile. Use the + full path to the tasks assembly for UsingTasks. + 2010-03-04 Ankit Jain * AssignTargetPathTest.cs (CreateProjectString): Remove the diff --git a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreateCSharpManifestResourceNameTest.cs b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreateCSharpManifestResourceNameTest.cs index 150104c662..47f2b75e14 100755 --- a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreateCSharpManifestResourceNameTest.cs +++ b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreateCSharpManifestResourceNameTest.cs @@ -235,9 +235,9 @@ namespace MonoTests.Microsoft.Build.Tasks Project project = engine.CreateNewProject (); TestMessageLogger logger = new TestMessageLogger (); engine.RegisterLogger (logger); - Console.WriteLine (projectText); project.LoadXml (projectText); if (!project.Build ("1")) { + Console.WriteLine (projectText); logger.DumpMessages (); Assert.Fail ("Build failed"); } @@ -283,11 +283,16 @@ namespace MonoTests.Microsoft.Build.Tasks sb.AppendFormat (" RootNamespace = \"{0}\"", rootNamespace); sb.Append (">\n \t\t\t\n"); sb.Append ("\t\t\n\t\n"); - sb.Append ("\t\n"); + sb.Append ("\t" + GetUsingTask ("CreateCSharpManifestResourceName")); sb.Append (""); return sb.ToString (); } + + string GetUsingTask (string taskName) + { + return ""; + } + } } diff --git a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreateItemTest.cs b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreateItemTest.cs index d16c54572a..cfe90118c3 100755 --- a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreateItemTest.cs +++ b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreateItemTest.cs @@ -252,6 +252,7 @@ namespace MonoTests.Microsoft.Build.Tasks { } +#if NET_3_5 || NET_4_0 [Test] public void TestItemsWithWildcards () { Engine engine = new Engine (Consts.BinPath); @@ -274,7 +275,7 @@ namespace MonoTests.Microsoft.Build.Tasks { }; string documentString = @" - + dir\**\*.dll *\x*.dll @@ -318,6 +319,7 @@ namespace MonoTests.Microsoft.Build.Tasks { Directory.Delete (basedir, true); } } +#endif void CreateDirectoriesAndFiles (string basedir, string[] dirs, string[] files) { foreach (string dir in dirs) diff --git a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreateVisualBasicManifestResourceNameTest.cs b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreateVisualBasicManifestResourceNameTest.cs index bb94c5c3af..b5b4b18b87 100755 --- a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreateVisualBasicManifestResourceNameTest.cs +++ b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/CreateVisualBasicManifestResourceNameTest.cs @@ -235,9 +235,9 @@ namespace MonoTests.Microsoft.Build.Tasks Project project = engine.CreateNewProject (); TestMessageLogger logger = new TestMessageLogger (); engine.RegisterLogger (logger); - Console.WriteLine (projectText); project.LoadXml (projectText); if (!project.Build ("1")) { + Console.WriteLine (projectText); logger.DumpMessages (); Assert.Fail ("Build failed"); } @@ -283,11 +283,16 @@ namespace MonoTests.Microsoft.Build.Tasks sb.AppendFormat (" RootNamespace = \"{0}\"", rootNamespace); sb.Append (">\n \t\t\t\n"); sb.Append ("\t\t\n\t\n"); - sb.Append ("\t\n"); + sb.Append ("\t" + GetUsingTask ("CreateVisualBasicManifestResourceName")); sb.Append (""); return sb.ToString (); } + + string GetUsingTask (string taskName) + { + return ""; + } + } } diff --git a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/FindAppConfigFileTest.cs b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/FindAppConfigFileTest.cs index d6b9d0aa4d..5aaa23086b 100644 --- a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/FindAppConfigFileTest.cs +++ b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/FindAppConfigFileTest.cs @@ -25,6 +25,8 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +#if NET_3_5 + using System; using System.Collections; using Microsoft.Build.BuildEngine; @@ -85,7 +87,7 @@ namespace MonoTests.Microsoft.Build.Tasks { void CheckOutput (string[] primary_list, string[] secondary_list, string expected) { StringBuilder sb = new StringBuilder (); - sb.Append (@""); + sb.Append (@""); sb.Append ("\t"); if (primary_list != null) foreach (string s in primary_list) @@ -124,4 +126,4 @@ namespace MonoTests.Microsoft.Build.Tasks { } } } - +#endif diff --git a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/RemoveDuplicatesTest.cs b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/RemoveDuplicatesTest.cs index b4c17a8f37..6c1975c804 100644 --- a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/RemoveDuplicatesTest.cs +++ b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/RemoveDuplicatesTest.cs @@ -44,7 +44,7 @@ namespace MonoTests.Microsoft.Build.Tasks public void Test1 () { string documentString = @" - + diff --git a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/TaskBatchingTest.cs b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/TaskBatchingTest.cs index 6bfaae755e..e854812b76 100755 --- a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/TaskBatchingTest.cs +++ b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/TaskBatchingTest.cs @@ -40,6 +40,12 @@ namespace MonoTests.Microsoft.Build.Tasks [TestFixture] public class TaskBatchingTest { + string projectHeader; + public TaskBatchingTest () + { + projectHeader = @""; + } + [Test] public void Test1 () { @@ -548,7 +554,7 @@ namespace MonoTests.Microsoft.Build.Tasks // batching should happen only on basis of the task attributes, // and not the resolved expression values public void TestBatching1 () { - string projectString = @" + string projectString = projectHeader + @" @@ -584,7 +590,7 @@ namespace MonoTests.Microsoft.Build.Tasks // batching should happen only on basis of the task attributes, // and not the resolved expression values public void TestConditionalBatching2 () { - string projectString = @" + string projectString = projectHeader + @" @@ -614,7 +620,7 @@ namespace MonoTests.Microsoft.Build.Tasks [Test] public void TestBatchingWithUnbatchedItems () { - string projectString = @" + string projectString = projectHeader + @" @@ -651,7 +657,7 @@ namespace MonoTests.Microsoft.Build.Tasks [Test] public void TestPropertiesWithBatchedReferences () { - string projectString = @" + string projectString = projectHeader + @" @@ -693,7 +699,7 @@ namespace MonoTests.Microsoft.Build.Tasks [Test] public void TestPropertiesWithDynamicItems () { - string projectString = @" + string projectString = projectHeader + @" @@ -748,7 +754,7 @@ namespace MonoTests.Microsoft.Build.Tasks [Test] public void TestTargetInvocationFromBatchedTask () { - string projectString = @" + string projectString = projectHeader + @" @@ -799,7 +805,7 @@ namespace MonoTests.Microsoft.Build.Tasks [Test] public void TestTargetInvocationFromBatchedTarget () { - string projectString = @" + string projectString = projectHeader + @" @@ -864,7 +870,7 @@ namespace MonoTests.Microsoft.Build.Tasks [Test] public void TestBatchingWithUnqualifiedMetadataReference () { - string projectString = @" + string projectString = projectHeader + @" 1 2 diff --git a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/WriteLinesToFileTest.cs b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/WriteLinesToFileTest.cs index 62c03ac7e6..82d4471a53 100755 --- a/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/WriteLinesToFileTest.cs +++ b/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/WriteLinesToFileTest.cs @@ -159,7 +159,7 @@ namespace MonoTests.Microsoft.Build.Tasks { Project project; StringBuilder sb = new StringBuilder (); - sb.Append (@" + sb.Append (@" "); diff --git a/class/Microsoft.Build.Tasks/Test/test-config-file-net-3.5 b/class/Microsoft.Build.Tasks/Test/test-config-file-net-3.5 new file mode 100644 index 0000000000..7756bca8df --- /dev/null +++ b/class/Microsoft.Build.Tasks/Test/test-config-file-net-3.5 @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/class/Microsoft.Build.Tasks/Test/test-config-file-net-4.0 b/class/Microsoft.Build.Tasks/Test/test-config-file-net-4.0 new file mode 100644 index 0000000000..3c78f3b4ec --- /dev/null +++ b/class/Microsoft.Build.Tasks/Test/test-config-file-net-4.0 @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/class/Microsoft.Build.Utilities/ChangeLog b/class/Microsoft.Build.Utilities/ChangeLog index d82c003790..19ffbef5c9 100644 --- a/class/Microsoft.Build.Utilities/ChangeLog +++ b/class/Microsoft.Build.Utilities/ChangeLog @@ -1,3 +1,10 @@ +2010-04-03 Ankit Jain + + * Makefile: Import tools/xbuild/xbuild_targets.make, which copies + the target and tasks file in the correct place, to allow running + tests with different toolsversion. + Use the correct target assembly name for 4.0 profile. + 2010-02-10 Ankit Jain * Microsoft.Build.Utilities.dll.sources: Add ProcessStringDictionary.cs diff --git a/class/Microsoft.Build.Utilities/Makefile b/class/Microsoft.Build.Utilities/Makefile index bbfc0a9f1a..a600ff9b67 100644 --- a/class/Microsoft.Build.Utilities/Makefile +++ b/class/Microsoft.Build.Utilities/Makefile @@ -12,6 +12,10 @@ endif ifeq (3.5, $(FRAMEWORK_VERSION)) LIBRARY_NAME = Microsoft.Build.Utilities.v3.5.dll +else +ifeq (4.0, $(FRAMEWORK_VERSION)) +LIBRARY_NAME = Microsoft.Build.Utilities.v4.0.dll +endif endif LIB_MCS_FLAGS = \ @@ -21,4 +25,8 @@ LIB_MCS_FLAGS = \ TEST_MCS_FLAGS = /r:Microsoft.Build.Framework.dll +export TESTING_MONO=a +XBUILD_DIR=../../tools/xbuild +include $(XBUILD_DIR)/xbuild_targets.make + include ../../build/library.make diff --git a/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ChangeLog b/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ChangeLog index d7f994b30d..4b6f4c5c6a 100644 --- a/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ChangeLog +++ b/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ChangeLog @@ -1,3 +1,12 @@ +2010-04-03 Ankit Jain + + * TargetDotNetFrameworkVersion.cs: Add Version40 . + * Task.cs (BuildEngine2): New. + * ToolLocationHelper.cs: Use class/lib/net_* as the path + for the assemblies and targets when running tests. + Environment variable TESTING_MONO is set for testing. + This allows a 4.0 xbuild to build 2.0/3.5 projects. + 2010-02-19 Ankit Jain * TaskItem.cs: Track api changes. diff --git a/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/TargetDotNetFrameworkVersion.cs b/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/TargetDotNetFrameworkVersion.cs index 451e40ef14..60cd2dba3d 100644 --- a/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/TargetDotNetFrameworkVersion.cs +++ b/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/TargetDotNetFrameworkVersion.cs @@ -37,7 +37,12 @@ namespace Microsoft.Build.Utilities Version20, Version30, Version35, +#if NET_4_0 + Version40, + VersionLatest = Version40 +#else VersionLatest = Version35 +#endif } } diff --git a/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/Task.cs b/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/Task.cs index 6227634205..a529e1fafa 100644 --- a/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/Task.cs +++ b/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/Task.cs @@ -70,6 +70,10 @@ namespace Microsoft.Build.Utilities } } + public IBuildEngine2 BuildEngine2 { + get { return buildEngine as IBuildEngine2; } + } + protected string HelpKeywordPrefix { get { return helpKeywordPrefix; diff --git a/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolLocationHelper.cs b/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolLocationHelper.cs index 3c13207602..a6c807cfbd 100644 --- a/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolLocationHelper.cs +++ b/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolLocationHelper.cs @@ -50,13 +50,24 @@ namespace Microsoft.Build.Utilities t2 = t1.Parent; lib_mono_dir = t2.FullName; + if (Environment.GetEnvironmentVariable ("TESTING_MONO") != null) { + mono_dir = new string [] { + Path.Combine (lib_mono_dir, "net_1_0"), + Path.Combine (lib_mono_dir, "net_2_0"), + Path.Combine (lib_mono_dir, "net_2_0"), + Path.Combine (lib_mono_dir, "net_3_5"), + Path.Combine (lib_mono_dir, "net_4_0") + }; + } else { + mono_dir = new string [] { + Path.Combine (lib_mono_dir, "1.0"), + Path.Combine (lib_mono_dir, "2.0"), + Path.Combine (lib_mono_dir, "2.0"), + Path.Combine (lib_mono_dir, "3.5"), + Path.Combine (lib_mono_dir, "4.0") + }; + } - mono_dir = new string [] { - Path.Combine (lib_mono_dir, "1.0"), - Path.Combine (lib_mono_dir, "2.0"), - Path.Combine (lib_mono_dir, "2.0"), - Path.Combine (lib_mono_dir, "3.5") - }; } [MonoTODO] diff --git a/tools/ChangeLog b/tools/ChangeLog index 6906d62759..115c18f02f 100644 --- a/tools/ChangeLog +++ b/tools/ChangeLog @@ -1,3 +1,7 @@ +2010-04-03 Ankit Jain + + * Makefile: Move xbuild from net_4_0_dirs to per_profile_dirs. + 2010-03-16 Jb Evain * Makefile: rename the net_2_1 profile to moonlight. diff --git a/tools/Makefile b/tools/Makefile index 34abc62fc5..42d150b785 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -13,13 +13,13 @@ per_profile_dirs = \ mono-service \ mono-xsd \ resgen \ - wsdl + wsdl \ + xbuild net_4_0_dirs := \ $(per_profile_dirs) \ corcompare \ mono-xmltool \ - xbuild \ mdoc \ mono-shlib-cop \ sgen \ diff --git a/tools/xbuild/ChangeLog b/tools/xbuild/ChangeLog index 43b9742558..963048dfbf 100644 --- a/tools/xbuild/ChangeLog +++ b/tools/xbuild/ChangeLog @@ -1,3 +1,27 @@ +2010-04-03 Ankit Jain + + * Main.cs (Execute): If toolsversion is specified on the command line, + then use that. + * Parameters.cs: Read toolsversion from the command line ('/tv:..') . + * SolutionParser.cs: Infer ToolsVersion from the sln version. + Set ToolsVersion property of the MSBuild tasks, in the generated + .sln.proj file, for building the projects. + + * xbuild/Microsoft.Common.tasks: Move to .. + * xbuild/2.0/Microsoft.Common.tasks: .. here. + * xbuild/3.5/Microsoft.Common.tasks: New. + * xbuild/4.0/Microsoft.Common.tasks: New. + Use the corresponding 3.5/4.0 tasks assembly. + + * xbuild_targets.make: Copies the target and tasks file in the correct + place, to allow running tests with different toolsversion. + * Makefile: Import xbuild_targets.make . Use correct assembly names for + Utilities assembly, for 3.5/4.0 profiles. + Install the correct Microsoft.Common.tasks file for the profile. + Copy xbuild.exe to class/lib/$(PROFILE), so that it can find other + profile dirs as relative path. + (EXTRA_DISTFILES): Add the new Microsoft.Common.tasks files. + 2010-03-04 Ankit Jain * CommandLineException.cs (Message): Include the inner exception message diff --git a/tools/xbuild/Main.cs b/tools/xbuild/Main.cs index 8c8cd6c309..89c84632a8 100644 --- a/tools/xbuild/Main.cs +++ b/tools/xbuild/Main.cs @@ -44,7 +44,6 @@ namespace Mono.XBuild.CommandLine { Parameters parameters; string[] args; - string binPath; string defaultSchema; Engine engine; @@ -61,11 +60,11 @@ namespace Mono.XBuild.CommandLine { public MainClass () { - binPath = ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20); + string binPath = ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20); defaultSchema = Path.Combine (binPath, "Microsoft.Build.xsd"); - parameters = new Parameters (binPath); + parameters = new Parameters (); } - + public void Execute () { bool result = false; @@ -79,7 +78,14 @@ namespace Mono.XBuild.CommandLine { if (parameters.DisplayVersion) ErrorUtilities.ShowVersion (false); - engine = new Engine (binPath); + //FIXME: cmd line arg to set toolsversion + engine = Engine.GlobalEngine; + if (!String.IsNullOrEmpty (parameters.ToolsVersion)) { + if (engine.Toolsets [parameters.ToolsVersion] == null) + ErrorUtilities.ReportError (0, String.Format ("Unknown tools version : {0}", parameters.ToolsVersion)); + + engine.DefaultToolsVersion = parameters.ToolsVersion; + } engine.GlobalProperties = this.parameters.Properties; diff --git a/tools/xbuild/Makefile b/tools/xbuild/Makefile index b1122842be..da7a5bc766 100644 --- a/tools/xbuild/Makefile +++ b/tools/xbuild/Makefile @@ -3,11 +3,26 @@ SUBDIRS = include ../../build/rules.make HAS_NUNIT_TEST = yes -LOCAL_MCS_FLAGS = -r:Microsoft.Build.Framework.dll -r:Microsoft.Build.Utilities.dll -r:Microsoft.Build.Engine.dll -PROGRAM = xbuild.exe +ifeq (3.5, $(FRAMEWORK_VERSION)) +NAME_SUFFIX = .v3.5 +ASSEMBLY_VERSION = 3.5.0.0 +else +ifeq (4.0, $(FRAMEWORK_VERSION)) +NAME_SUFFIX = .v4.0 +ASSEMBLY_VERSION = 4.0.0.0 +endif +endif + +LOCAL_MCS_FLAGS = -r:Microsoft.Build.Framework.dll -r:Microsoft.Build.Utilities$(NAME_SUFFIX).dll -r:Microsoft.Build.Engine.dll +PROGRAM = $(topdir)/class/lib/$(PROFILE)/xbuild.exe include ../../build/executable.make +CLEAN_FILES= xbuild.exe xbuild.exe.mdb + +XBUILD_DIR=. +include $(XBUILD_DIR)/xbuild_targets.make + install-local: install-extras WEBAPP_DIR = Microsoft/VisualStudio/v9.0/WebApplications @@ -15,7 +30,7 @@ EXTRAS_DIR = $(mono_libdir)/mono/$(FRAMEWORK_VERSION) install-extras: $(MKINSTALLDIRS) $(DESTDIR)$(EXTRAS_DIR) $(INSTALL_DATA) xbuild/xbuild.rsp $(DESTDIR)$(EXTRAS_DIR) - $(INSTALL_DATA) xbuild/Microsoft.Common.tasks $(DESTDIR)$(EXTRAS_DIR) + $(INSTALL_DATA) xbuild/$(FRAMEWORK_VERSION)/Microsoft.Common.tasks $(DESTDIR)$(EXTRAS_DIR) $(INSTALL_DATA) xbuild/Microsoft.Build.xsd $(DESTDIR)$(EXTRAS_DIR) $(INSTALL_DATA) xbuild/Microsoft.Common.targets $(DESTDIR)$(EXTRAS_DIR) $(INSTALL_DATA) xbuild/Microsoft.CSharp.targets $(DESTDIR)$(EXTRAS_DIR) @@ -29,7 +44,9 @@ install-extras: EXTRA_DISTFILES = \ xbuild/xbuild.rsp \ - xbuild/Microsoft.Common.tasks \ + xbuild/2.0/Microsoft.Common.tasks \ + xbuild/3.5/Microsoft.Common.tasks \ + xbuild/4.0/Microsoft.Common.tasks \ xbuild/Microsoft.Build.xsd \ xbuild/Microsoft.CSharp.targets \ xbuild/Microsoft.Common.targets \ diff --git a/tools/xbuild/Parameters.cs b/tools/xbuild/Parameters.cs index 0dab523418..8cb4f5d749 100644 --- a/tools/xbuild/Parameters.cs +++ b/tools/xbuild/Parameters.cs @@ -56,10 +56,11 @@ namespace Mono.XBuild.CommandLine { string[] targets; bool validate; string validationSchema; + string toolsVersion; string responseFile; - public Parameters (string binPath) + public Parameters () { consoleLoggerParameters = ""; displayHelp = false; @@ -237,6 +238,8 @@ namespace Mono.XBuild.CommandLine { ProcessConsoleLoggerParameters (s); } else if (s.StartsWith ("/validate:") || s.StartsWith ("/val:")) { ProcessValidate (s); + } else if (s.StartsWith ("/toolsversion:") || s.StartsWith ("/tv:")) { + ToolsVersion = s.Split (':') [1]; } else return false; break; @@ -386,6 +389,11 @@ namespace Mono.XBuild.CommandLine { public string ValidationSchema { get { return validationSchema; } } + + public string ToolsVersion { + get { return toolsVersion; } + private set { toolsVersion = value; } + } } } diff --git a/tools/xbuild/SolutionParser.cs b/tools/xbuild/SolutionParser.cs index 9ebff1e0a7..c4b9482100 100644 --- a/tools/xbuild/SolutionParser.cs +++ b/tools/xbuild/SolutionParser.cs @@ -91,6 +91,7 @@ namespace Mono.XBuild.CommandLine { static string guidExpression = "{[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}}"; + static Regex slnVersionRegex = new Regex (@"Microsoft Visual Studio Solution File, Format Version (\d?\d.\d\d)"); static Regex projectRegex = new Regex ("Project\\(\"(" + guidExpression + ")\"\\) = \"(.*?)\", \"(.*?)\", \"(" + guidExpression + ")\"(\\s*?)((\\s*?)ProjectSection\\((.*?)\\) = (.*?)EndProjectSection(\\s*?))*(\\s*?)EndProject?", RegexOptions.Singleline); static Regex projectDependenciesRegex = new Regex ("ProjectSection\\((.*?)\\) = \\w*(.*?)EndProjectSection", RegexOptions.Singleline); static Regex projectDependencyRegex = new Regex ("\\s*(" + guidExpression + ") = (" + guidExpression + ")"); @@ -115,6 +116,14 @@ namespace Mono.XBuild.CommandLine { AddGeneralSettings (file, p); StreamReader reader = new StreamReader (file); + string slnVersion = GetSlnFileVersion (reader); + if (slnVersion == "11.00") + p.DefaultToolsVersion = "4.0"; + else if (slnVersion == "10.00") + p.DefaultToolsVersion = "3.5"; + else + p.DefaultToolsVersion = "2.0"; + string line = reader.ReadToEnd (); line = line.Replace ("\r\n", "\n"); string solutionDir = Path.GetDirectoryName (file); @@ -260,6 +269,30 @@ namespace Mono.XBuild.CommandLine { AddSolutionTargets (p, num_levels, websiteProjectInfos.Values); } + string GetSlnFileVersion (StreamReader reader) + { + string strVersion = null; + string strInput = null; + Match match; + + strInput = reader.ReadLine(); + if (strInput == null) + return null; + + match = slnVersionRegex.Match(strInput); + if (!match.Success) { + strInput = reader.ReadLine(); + if (strInput == null) + return null; + match = slnVersionRegex.Match (strInput); + } + + if (match.Success) + return match.Groups[1].Value; + + return null; + } + void AddGeneralSettings (string solutionFile, Project p) { p.DefaultTargets = "Build"; @@ -692,6 +725,7 @@ namespace Mono.XBuild.CommandLine { if (projectTargetInfo.Build) { task = target.AddNewTask ("MSBuild"); task.SetParameterValue ("Projects", project.FileName); + task.SetParameterValue ("ToolsVersion", "$(ProjectToolsVersion)"); if (buildTarget != "Build") task.SetParameterValue ("Targets", buildTarget); @@ -782,6 +816,7 @@ namespace Mono.XBuild.CommandLine { task = t.AddNewTask ("MSBuild"); task.SetParameterValue ("Condition", String.Format ("'@({0})' != ''", level_str)); task.SetParameterValue ("Projects", String.Format ("@({0})", level_str)); + task.SetParameterValue ("ToolsVersion", "$(ProjectToolsVersion)"); task.SetParameterValue ("Properties", string.Format ("Configuration=%(Configuration); Platform=%(Platform); BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)")); if (buildTarget != "Build") diff --git a/tools/xbuild/xbuild/Microsoft.Common.tasks b/tools/xbuild/xbuild/2.0/Microsoft.Common.tasks similarity index 100% rename from tools/xbuild/xbuild/Microsoft.Common.tasks rename to tools/xbuild/xbuild/2.0/Microsoft.Common.tasks diff --git a/tools/xbuild/xbuild/3.5/Microsoft.Common.tasks b/tools/xbuild/xbuild/3.5/Microsoft.Common.tasks new file mode 100644 index 0000000000..a044ad2e6c --- /dev/null +++ b/tools/xbuild/xbuild/3.5/Microsoft.Common.tasks @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/xbuild/xbuild/4.0/Microsoft.Common.tasks b/tools/xbuild/xbuild/4.0/Microsoft.Common.tasks new file mode 100644 index 0000000000..b494b58bda --- /dev/null +++ b/tools/xbuild/xbuild/4.0/Microsoft.Common.tasks @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/xbuild/xbuild_targets.make b/tools/xbuild/xbuild_targets.make new file mode 100644 index 0000000000..917eee5ff1 --- /dev/null +++ b/tools/xbuild/xbuild_targets.make @@ -0,0 +1,21 @@ +test-local: copy-targets + +copy-targets: + for p in net_2_0 net_3_5 net_4_0; do \ + cp $(XBUILD_DIR)/xbuild/Microsoft.Common.targets $(topdir)/class/lib/$$p; \ + cp $(XBUILD_DIR)/xbuild/Microsoft.CSharp.targets $(topdir)/class/lib/$$p; \ + cp $(XBUILD_DIR)/xbuild/Microsoft.VisualBasic.targets $(topdir)/class/lib/$$p; \ + done + cp $(XBUILD_DIR)/xbuild/2.0/Microsoft.Common.tasks $(topdir)/class/lib/net_2_0 + cp $(XBUILD_DIR)/xbuild/3.5/Microsoft.Common.tasks $(topdir)/class/lib/net_3_5 + cp $(XBUILD_DIR)/xbuild/4.0/Microsoft.Common.tasks $(topdir)/class/lib/net_4_0 + +clean-local: clean-target-files + +clean-target-files: + for p in net_2_0 net_3_5 net_4_0; do \ + rm -f $(topdir)/class/lib/$$p/Microsoft.Common.targets; \ + rm -f $(topdir)/class/lib/$$p/Microsoft.CSharp.targets; \ + rm -f $(topdir)/class/lib/$$p/Microsoft.VisualBasic.targets; \ + rm -f $(topdir)/class/lib/$$p/Microsoft.Common.tasks; \ + done -- 2.11.4.GIT