[xbuild] Add hooks for extending .sln builds.
authorAnkit Jain <radical@corewars.org>
Thu, 3 Mar 2011 17:41:57 +0000 (23:11 +0530)
committerAnkit Jain <radical@corewars.org>
Thu, 3 Mar 2011 19:20:31 +0000 (00:50 +0530)
Add hooks in the .sln.proj generated from .sln files.

1. It imports
   "$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\SolutionFile\ImportBefore\*"
   and
   "$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\SolutionFile\ImportAfter\*"
   This is done only in case of 4.0 projects, as imports with wildcard
   is a 4.0 feature.

2. And it imports before.Foo.sln.targets and after.Foo.sln.targets from
   the same dir as the .sln file.

mcs/tools/xbuild/SolutionParser.cs

index b9f5090e2a4e8162ab250abdd8c861d88b932751..67bce1c6afb0519ab3f4d138f1cbbc1f32b20a8d 100644 (file)
@@ -114,6 +114,8 @@ namespace Mono.XBuild.CommandLine {
                public void ParseSolution (string file, Project p, RaiseWarningHandler RaiseWarning)
                {
                        this.RaiseWarning = RaiseWarning;
+                       EmitBeforeImports (p, file);
+
                        AddGeneralSettings (file, p);
 
                        StreamReader reader = new StreamReader (file);
@@ -305,6 +307,8 @@ namespace Mono.XBuild.CommandLine {
                        AddWebsiteProperties (p, websiteProjectInfos, projectInfos);
                        AddValidateSolutionConfiguration (p);
 
+                       EmitAfterImports (p, file);
+
                        AddGetFrameworkPathTarget (p);
                        AddWebsiteTargets (p, websiteProjectInfos, projectInfos, infosByLevel, solutionTargets);
                        AddProjectTargets (p, solutionTargets, projectInfos);
@@ -334,6 +338,30 @@ namespace Mono.XBuild.CommandLine {
                         return null;
                 }
 
+               void EmitBeforeImports (Project p, string file)
+               {
+#if NET_4_0
+                       p.AddNewImport ("$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\SolutionFile\\ImportBefore\\*",
+                                       "'$(ImportByWildcardBeforeSolution)' != 'false' and " +
+                                       "Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\SolutionFile\\ImportBefore')");
+#endif
+
+                       string before_filename = Path.Combine (Path.GetDirectoryName (file), "before." + Path.GetFileName (file) + ".targets");
+                       p.AddNewImport (before_filename, String.Format ("Exists ('{0}')", before_filename));
+               }
+
+               void EmitAfterImports (Project p, string file)
+               {
+#if NET_4_0
+                       p.AddNewImport ("$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\SolutionFile\\ImportAfter\\*",
+                                       "'$(ImportByWildcardAfterSolution)' != 'false' and " +
+                                       "Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\SolutionFile\\ImportAfter')");
+#endif
+
+                       string after_filename = Path.Combine (Path.GetDirectoryName (file), "after." + Path.GetFileName (file) + ".targets");
+                       p.AddNewImport (after_filename, String.Format ("Exists ('{0}')", after_filename));
+               }
+
                void AddGeneralSettings (string solutionFile, Project p)
                {
                        p.DefaultTargets = "Build";