|
|
@ -3,9 +3,9 @@ |
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
using System.IO; |
|
|
|
using System.Reflection; |
|
|
|
using System.Reflection; |
|
|
|
using System.Text; |
|
|
|
using System.Text; |
|
|
|
|
|
|
|
|
|
|
|
using MSjogren.GacTool.FusionNative; |
|
|
|
using MSjogren.GacTool.FusionNative; |
|
|
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.SharpDevelop.Dom |
|
|
|
namespace ICSharpCode.SharpDevelop.Dom |
|
|
@ -16,25 +16,15 @@ namespace ICSharpCode.SharpDevelop.Dom |
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public static class GacInterop |
|
|
|
public static class GacInterop |
|
|
|
{ |
|
|
|
{ |
|
|
|
volatile static string cachedGacPathV2; |
|
|
|
static readonly string cachedGacPathV2 = Fusion.GetGacPath(false); |
|
|
|
volatile static string cachedGacPathV4; |
|
|
|
static readonly string cachedGacPathV4 = Fusion.GetGacPath(true); |
|
|
|
|
|
|
|
|
|
|
|
public static string GacRootPathV2 { |
|
|
|
public static string GacRootPathV2 { |
|
|
|
get { |
|
|
|
get { return cachedGacPathV2; } |
|
|
|
if (cachedGacPathV2 == null) { |
|
|
|
|
|
|
|
cachedGacPathV2 = Fusion.GetGacPath(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return cachedGacPathV2; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static string GacRootPathV4 { |
|
|
|
public static string GacRootPathV4 { |
|
|
|
get { |
|
|
|
get { return cachedGacPathV4; } |
|
|
|
if (cachedGacPathV4 == null) { |
|
|
|
|
|
|
|
cachedGacPathV4 = Fusion.GetGacPath(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return cachedGacPathV4; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static bool IsWithinGac(string assemblyLocation) |
|
|
|
public static bool IsWithinGac(string assemblyLocation) |
|
|
@ -135,5 +125,74 @@ namespace ICSharpCode.SharpDevelop.Dom |
|
|
|
} |
|
|
|
} |
|
|
|
return new DomAssemblyName(best); |
|
|
|
return new DomAssemblyName(best); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region FindAssemblyInGac
|
|
|
|
|
|
|
|
// This region is based on code from Mono.Cecil:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Author:
|
|
|
|
|
|
|
|
// Jb Evain (jbevain@gmail.com)
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Copyright (c) 2008 - 2010 Jb Evain
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static readonly string[] gac_paths = { GacInterop.GacRootPathV2, GacInterop.GacRootPathV4 }; |
|
|
|
|
|
|
|
static readonly string[] gacs = { "GAC_MSIL", "GAC_32", "GAC" }; |
|
|
|
|
|
|
|
static readonly string[] prefixes = { string.Empty, "v4.0_" }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Gets the file name for an assembly stored in the GAC.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public static string FindAssemblyInNetGac (DomAssemblyName reference) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// without public key, it can't be in the GAC
|
|
|
|
|
|
|
|
if (reference.PublicKeyToken == null) |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) { |
|
|
|
|
|
|
|
for (int j = 0; j < gacs.Length; j++) { |
|
|
|
|
|
|
|
var gac = Path.Combine (gac_paths [i], gacs [j]); |
|
|
|
|
|
|
|
var file = GetAssemblyFile (reference, prefixes [i], gac); |
|
|
|
|
|
|
|
if (File.Exists (file)) |
|
|
|
|
|
|
|
return file; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static string GetAssemblyFile (DomAssemblyName reference, string prefix, string gac) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var gac_folder = new StringBuilder () |
|
|
|
|
|
|
|
.Append (prefix) |
|
|
|
|
|
|
|
.Append (reference.Version) |
|
|
|
|
|
|
|
.Append ("__"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gac_folder.Append (reference.PublicKeyToken); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Path.Combine ( |
|
|
|
|
|
|
|
Path.Combine ( |
|
|
|
|
|
|
|
Path.Combine (gac, reference.ShortName), gac_folder.ToString ()), |
|
|
|
|
|
|
|
reference.ShortName + ".dll"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|