Created
September 11, 2015 16:16
-
-
Save mauroa/525216234081d1fd8ebc to your computer and use it in GitHub Desktop.
MSBuild ToolLocationHelper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while (!string.IsNullOrEmpty(path)) | |
{ | |
path = ChainReferenceAssemblyPath(path); | |
if (!string.IsNullOrEmpty(path)) | |
{ | |
if (list.Contains(path)) | |
{ | |
return list; | |
} | |
list.Add(path); | |
} | |
else if (path == null) | |
{ | |
list.Clear(); | |
return list; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static string ChainReferenceAssemblyPath(string targetFrameworkDirectory) | |
{ | |
string fullPath = Path.GetFullPath(targetFrameworkDirectory); | |
lock (locker) | |
{ | |
chainedReferenceAssemblyPath = chainedReferenceAssemblyPath ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |
cachedTargetFrameworkDisplayNames = cachedTargetFrameworkDisplayNames ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |
string str2 = null; | |
if (chainedReferenceAssemblyPath.TryGetValue(fullPath, out str2)) | |
{ | |
return str2; | |
} | |
} | |
string path = Path.Combine(Path.Combine(fullPath, "RedistList"), "FrameworkList.xml"); | |
if (!File.Exists(path)) | |
{ | |
lock (locker) | |
{ | |
chainedReferenceAssemblyPath[fullPath] = null; | |
cachedTargetFrameworkDisplayNames[fullPath] = null; | |
} | |
return null; | |
} | |
string str5 = null; | |
string str6 = null; | |
try | |
{ | |
using (XmlTextReader reader = new XmlTextReader(path)) | |
{ | |
reader.DtdProcessing = DtdProcessing.Ignore; | |
while (reader.Read()) | |
{ | |
if ((reader.NodeType == XmlNodeType.Element) && string.Equals(reader.Name, "FileList", StringComparison.OrdinalIgnoreCase)) | |
{ | |
reader.MoveToFirstAttribute(); | |
do | |
{ | |
if (string.Equals(reader.Name, "IncludeFramework", StringComparison.OrdinalIgnoreCase)) | |
{ | |
str5 = reader.Value; | |
} | |
else if (string.Equals(reader.Name, "Name", StringComparison.OrdinalIgnoreCase)) | |
{ | |
str6 = reader.Value; | |
} | |
} | |
while (reader.MoveToNextAttribute()); | |
reader.MoveToElement(); | |
goto Label_01CB; | |
} | |
} | |
} | |
} | |
catch (XmlException exception) | |
{ | |
ErrorUtilities.ThrowInvalidOperation("ToolsLocationHelper.InvalidRedistFile", new object[] { path, exception.Message }); | |
} | |
catch (Exception exception2) | |
{ | |
if (ExceptionHandling.NotExpectedException(exception2)) | |
{ | |
throw; | |
} | |
ErrorUtilities.ThrowInvalidOperation("ToolsLocationHelper.InvalidRedistFile", new object[] { path, exception2.Message }); | |
} | |
Label_01CB: | |
if (str6 != null) | |
{ | |
lock (locker) | |
{ | |
cachedTargetFrameworkDisplayNames[fullPath] = str6; | |
} | |
} | |
string fullName = string.Empty; | |
try | |
{ | |
if (!string.IsNullOrEmpty(str5)) | |
{ | |
fullName = fullPath; | |
fullName = Directory.GetParent(fullName).FullName; | |
fullName = Path.Combine(fullName, str5); | |
fullName = Path.GetFullPath(fullName); | |
if (!Directory.Exists(fullName)) | |
{ | |
fullName = null; | |
} | |
} | |
lock (locker) | |
{ | |
chainedReferenceAssemblyPath[fullPath] = fullName; | |
} | |
return fullName; | |
} | |
catch (Exception exception3) | |
{ | |
if (ExceptionHandling.IsCriticalException(exception3)) | |
{ | |
throw; | |
} | |
ErrorUtilities.ThrowInvalidOperation("ToolsLocationHelper.CouldNotCreateChain", new object[] { fullPath, fullName, exception3.Message }); | |
} | |
return null; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment