2 // ToolLocationHelper.cs:
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2005 Marek Sieradzki
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 namespace Microsoft.Build.Utilities
35 #if MICROSOFT_BUILD_DLL
40 static class ToolLocationHelper
42 static string lib_mono_dir;
43 static string [] mono_dir;
44 static bool runningOnDotNet;
46 static ToolLocationHelper ()
48 string assemblyLocation;
51 // /usr/local/lib/mono/1.0
52 assemblyLocation = Path.GetDirectoryName (typeof (object).Assembly.Location);
53 t1 = new DirectoryInfo (assemblyLocation);
58 lib_mono_dir = t2.FullName;
60 var windowsPath = Environment.GetFolderPath (Environment.SpecialFolder.Windows);
61 runningOnDotNet = !string.IsNullOrEmpty (windowsPath) && lib_mono_dir.StartsWith (windowsPath);
63 if (Environment.GetEnvironmentVariable ("TESTING_MONO") != null) {
64 mono_dir = new string [] {
65 Path.Combine (lib_mono_dir, "net_1_0"),
66 Path.Combine (lib_mono_dir, "net_2_0"),
67 Path.Combine (lib_mono_dir, "net_2_0"),
68 Path.Combine (lib_mono_dir, "net_3_5"),
69 // mono's 4.0 is not an actual framework directory with all tools etc
70 // it's simply reference assemblies. So like .NET we consider 4.5 to
71 // be a complete replacement for 4.0.
72 Path.Combine (lib_mono_dir, "net_4_x"),
73 Path.Combine (lib_mono_dir, "net_4_x"),
74 Path.Combine (lib_mono_dir, "net_4_x"),
75 Path.Combine (lib_mono_dir, "net_4_x")
77 } else if (runningOnDotNet) {
78 mono_dir = new string [] {
79 Path.Combine (lib_mono_dir, "v1.0.3705"),
80 Path.Combine (lib_mono_dir, "v2.0.50727"),
81 Path.Combine (lib_mono_dir, "v2.0.50727"),
82 Path.Combine (lib_mono_dir, "v3.5"),
83 Path.Combine (lib_mono_dir, "v4.0.30319"),
84 Path.Combine (lib_mono_dir, "v4.0.30319"),
85 Path.Combine (lib_mono_dir, "v4.0.30319"),
86 Path.Combine (lib_mono_dir, "v4.0.30319")
89 mono_dir = new string [] {
90 Path.Combine (lib_mono_dir, "1.0"),
91 Path.Combine (lib_mono_dir, "2.0"),
92 Path.Combine (lib_mono_dir, "2.0"),
93 Path.Combine (lib_mono_dir, "3.5"),
94 // see comment above regarding 4.0/4.5
95 Path.Combine (lib_mono_dir, "4.5"),
96 Path.Combine (lib_mono_dir, "4.5"),
97 Path.Combine (lib_mono_dir, "4.5"),
98 Path.Combine (lib_mono_dir, "4.5")
105 public static string GetDotNetFrameworkRootRegistryKey (TargetDotNetFrameworkVersion version)
107 throw new NotImplementedException ();
111 public static string GetDotNetFrameworkSdkInstallKeyValue (TargetDotNetFrameworkVersion version)
113 throw new NotImplementedException ();
117 public static string GetDotNetFrameworkVersionFolderPrefix (TargetDotNetFrameworkVersion version)
119 throw new NotImplementedException ();
122 public static string GetPathToDotNetFramework (TargetDotNetFrameworkVersion version)
124 return mono_dir [(int)version];
127 public static string GetPathToDotNetFrameworkFile (string fileName,
128 TargetDotNetFrameworkVersion version)
130 string dir = GetPathToDotNetFramework (version);
131 string file = Path.Combine (dir, fileName);
132 if (File.Exists (file))
135 //Mono doesn't ship multiple versions of tools that are backwards/forwards compatible
136 if (!runningOnDotNet) {
137 //most of the 3.5 tools are in the 2.0 directory
138 if (version == TargetDotNetFrameworkVersion.Version35)
139 return GetPathToDotNetFrameworkFile (fileName, TargetDotNetFrameworkVersion.Version20);
140 //unversioned tools are in the 4.5 directory
141 if (version == TargetDotNetFrameworkVersion.Version20)
142 return GetPathToDotNetFrameworkFile (fileName, (TargetDotNetFrameworkVersion)5);
148 public static string GetPathToDotNetFrameworkSdk (TargetDotNetFrameworkVersion version)
150 return GetPathToDotNetFramework (version);
154 public static string GetPathToDotNetFrameworkSdkFile (string fileName,
155 TargetDotNetFrameworkVersion version)
157 throw new NotImplementedException ();
160 public static string GetPathToStandardLibraries (string targetFrameworkIdentifier,
161 string targetFrameworkVersion,
162 string targetFrameworkProfile)
164 return GetPathToStandardLibraries (targetFrameworkIdentifier, targetFrameworkVersion, targetFrameworkProfile, null);
171 static string GetPathToStandardLibraries (string targetFrameworkIdentifier,
172 string targetFrameworkVersion,
173 string targetFrameworkProfile,
174 string platformTarget)
176 // FIXME: support platformTarget
177 if (platformTarget != null)
178 throw new NotImplementedException ("platformTarget support is not implemented");
180 var ext = Environment.GetEnvironmentVariable ("XBUILD_FRAMEWORK_FOLDERS_PATH");
181 var ret = ext != null ? GetPathToStandardLibrariesWith (ext, targetFrameworkIdentifier, targetFrameworkVersion, targetFrameworkProfile) : null;
182 return ret ?? GetPathToStandardLibrariesWith (Path.GetFullPath (Path.Combine (lib_mono_dir, "xbuild-frameworks")), targetFrameworkIdentifier, targetFrameworkVersion, targetFrameworkProfile);
185 static string GetPathToStandardLibrariesWith (string xbuildFxDir,
186 string targetFrameworkIdentifier,
187 string targetFrameworkVersion,
188 string targetFrameworkProfile)
190 var path = Path.Combine (xbuildFxDir, targetFrameworkIdentifier);
191 if (!string.IsNullOrEmpty (targetFrameworkVersion)) {
192 path = Path.Combine (path, targetFrameworkVersion);
193 if (!string.IsNullOrEmpty (targetFrameworkProfile))
194 path = Path.Combine (path, "Profile", targetFrameworkProfile);
196 if (!Directory.Exists (path))
198 var flist = Path.Combine (path, "RedistList", "FrameworkList.xml");
199 if (!File.Exists (flist))
201 var xml = XmlReader.Create (flist);
202 xml.MoveToContent ();
203 var targetFxDir = xml.GetAttribute ("TargetFrameworkDirectory");
204 targetFxDir = targetFxDir != null ? Path.GetFullPath (Path.Combine (path, "dummy", targetFxDir.Replace ('\\', Path.DirectorySeparatorChar))) : null;
205 if (Directory.Exists (targetFxDir))
207 // I'm not sure if this is completely valid assumption...
212 public static string GetPathToSystemFile (string fileName)
214 throw new NotImplementedException ();
218 public static string PathToSystem {
220 throw new NotImplementedException ();
225 public static string CurrentToolsVersion {
227 return XBuildConsts.Version;
231 public static string GetPathToBuildTools (string toolsVersion)
234 switch (toolsVersion) {
245 if (Environment.GetEnvironmentVariable ("TESTING_MONO") != null)
246 return Path.Combine (lib_mono_dir, path);
248 if (runningOnDotNet) {
249 //see http://msdn.microsoft.com/en-us/library/vstudio/bb397428(v=vs.120).aspx
250 var programFiles = Environment.GetFolderPath (Environment.SpecialFolder.ProgramFilesX86);
251 return Path.Combine (programFiles, "MSBuild", toolsVersion, "bin");
254 return Path.Combine (lib_mono_dir, "xbuild", toolsVersion, "bin");