From: Ankit Jain Date: Thu, 3 Mar 2011 17:41:57 +0000 (+0530) Subject: [xbuild] Add hooks for extending .sln builds. X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=9aba3ef7eb4949d46ee4f5f720a834e0e2e70e59 [xbuild] Add hooks for extending .sln builds. 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. --- diff --git a/mcs/tools/xbuild/SolutionParser.cs b/mcs/tools/xbuild/SolutionParser.cs index b9f5090e2a4..67bce1c6afb 100644 --- a/mcs/tools/xbuild/SolutionParser.cs +++ b/mcs/tools/xbuild/SolutionParser.cs @@ -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";