Browse Source

Use persistence for GAC assemblies loaded using Cecil.

Look for xml documentation files installed by the Vista SDK.
Allow loading MSBuild projects that don't specify IdGuid/default Configuration/default Platform.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2075 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
694abefe8e
  1. 15
      src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs
  2. 10
      src/Main/Base/Project/Src/Services/ParserService/ParserService.cs
  3. 39
      src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs
  4. 83
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/GacInterop.cs
  5. 17
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ProjectContentRegistry.cs
  6. 22
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ReflectionProjectContent.cs
  7. 4
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionLoader.cs

15
src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

@ -820,9 +820,24 @@ namespace ICSharpCode.SharpDevelop.Project @@ -820,9 +820,24 @@ namespace ICSharpCode.SharpDevelop.Project
this.ActiveConfiguration = GetEvaluatedProperty("Configuration") ?? this.ActiveConfiguration;
this.ActivePlatform = GetEvaluatedProperty("Platform") ?? this.ActivePlatform;
// Some projects do not specify default configuration/platform, so we have to set
// Configuration and Platform in the global properties to be sure these properties exist
project.GlobalProperties.SetProperty("Configuration", this.ActiveConfiguration, true);
project.GlobalProperties.SetProperty("Platform", this.ActivePlatform, true);
CreateItemsListFromMSBuild();
LoadConfigurationPlatformNamesFromMSBuild();
IdGuid = GetEvaluatedProperty("ProjectGuid");
if (IdGuid == null) {
// Fix projects that have nb GUID
IdGuid = Guid.NewGuid().ToString();
SetPropertyInternal(null, null, "ProjectGuid", IdGuid, PropertyStorageLocations.Base, true);
try {
// save fixed project
project.Save(fileName);
} catch {}
}
} finally {
isLoading = false;
}

10
src/Main/Base/Project/Src/Services/ParserService/ParserService.cs

@ -43,7 +43,6 @@ namespace ICSharpCode.SharpDevelop @@ -43,7 +43,6 @@ namespace ICSharpCode.SharpDevelop
#endif
Directory.CreateDirectory(domPersistencePath);
defaultProjectContentRegistry.ActivatePersistence(domPersistencePath);
ProjectService.SolutionClosed += ProjectServiceSolutionClosed;
}
}
@ -221,6 +220,15 @@ namespace ICSharpCode.SharpDevelop @@ -221,6 +220,15 @@ namespace ICSharpCode.SharpDevelop
{
LoggingService.Info("reParse thread started");
Thread.Sleep(100); // enable main thread to fill the queues completely
try {
ReparseProjectsInternal();
} catch (Exception ex) {
MessageService.ShowError(ex);
}
}
static void ReparseProjectsInternal()
{
bool parsing = false;
ParseProjectContent job;

39
src/Main/Core/Project/Src/Services/FileUtility/FileUtility.cs

@ -52,6 +52,9 @@ namespace ICSharpCode.Core @@ -52,6 +52,9 @@ namespace ICSharpCode.Core
}
}
/// <summary>
/// Gets the installation root of the .NET Framework (@"C:\Windows\Microsoft.NET\Framework\")
/// </summary>
public static string NETFrameworkInstallRoot {
get {
using (RegistryKey installRootKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework")) {
@ -61,28 +64,30 @@ namespace ICSharpCode.Core @@ -61,28 +64,30 @@ namespace ICSharpCode.Core
}
}
/// <summary>
/// Gets the Windows Vista SDK installation root. If the Vista SDK is not installed, the
/// .NET 2.0 SDK installation root is returned. If both are not installed, an empty string is returned.
/// </summary>
public static string NetSdkInstallRoot {
get {
using (RegistryKey installRootKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework")) {
object o = installRootKey.GetValue("sdkInstallRootv2.0");
return o == null ? String.Empty : o.ToString();
string val = String.Empty;
RegistryKey sdkRootKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0");
if (sdkRootKey != null) {
object o = sdkRootKey.GetValue("InstallationFolder");
val = o == null ? String.Empty : o.ToString();
sdkRootKey.Close();
}
}
}
public static string[] GetAvailableRuntimeVersions()
{
string installRoot = NETFrameworkInstallRoot;
string[] files = Directory.GetDirectories(installRoot);
List<string> runtimes = new List<string>();
foreach (string file in files) {
string runtime = Path.GetFileName(file);
if (runtime.StartsWith("v")) {
runtimes.Add(runtime);
if (val.Length == 0) {
RegistryKey installRootKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework");
if (installRootKey != null) {
object o = installRootKey.GetValue("sdkInstallRootv2.0");
val = o == null ? String.Empty : o.ToString();
installRootKey.Close();
}
}
return val;
}
return runtimes.ToArray();
}
public static string Combine(params string[] paths)

83
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/GacInterop.cs

@ -66,16 +66,24 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -66,16 +66,24 @@ namespace ICSharpCode.SharpDevelop.Dom
return l;
}
public static AssemblyName FindBestMatchingAssemblyName(string name)
/// <summary>
/// Gets the full display name of the GAC assembly of the specified short name
/// </summary>
public static GacAssemblyName FindBestMatchingAssemblyName(string name)
{
string[] info = name.Split(',');
string version = (info.Length > 1) ? info[1].Substring(info[1].LastIndexOf('=') + 1) : null;
string publicKey = (info.Length > 3) ? info[3].Substring(info[3].LastIndexOf('=') + 1) : null;
return FindBestMatchingAssemblyName(new GacAssemblyName(name));
}
public static GacAssemblyName FindBestMatchingAssemblyName(GacAssemblyName name)
{
string[] info;
string version = name.Version;
string publicKey = name.PublicKey;
IApplicationContext applicationContext = null;
IAssemblyEnum assemblyEnum = null;
IAssemblyName assemblyName;
Fusion.CreateAssemblyNameObject(out assemblyName, info[0], 0, 0);
Fusion.CreateAssemblyNameObject(out assemblyName, name.Name, 0, 0);
Fusion.CreateAssemblyEnum(out assemblyEnum, null, assemblyName, 2, 0);
List<string> names = new List<string>();
@ -115,7 +123,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -115,7 +123,7 @@ namespace ICSharpCode.SharpDevelop.Dom
}
}
if (best != null)
return new AssemblyName(best);
return new GacAssemblyName(best);
}
// use assembly with highest version
best = names[0];
@ -129,7 +137,68 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -129,7 +137,68 @@ namespace ICSharpCode.SharpDevelop.Dom
best = names[i];
}
}
return new AssemblyName(best);
return new GacAssemblyName(best);
}
}
public class GacAssemblyName : IEquatable<GacAssemblyName>
{
readonly string fullName;
readonly string[] info;
public GacAssemblyName(string fullName)
{
if (fullName == null)
throw new ArgumentNullException("fullName");
this.fullName = fullName;
info = fullName.Split(',');
}
public string Name {
get {
return info[0];
}
}
public string Version {
get {
return (info.Length > 1) ? info[1].Substring(info[1].LastIndexOf('=') + 1) : null;
}
}
public string PublicKey {
get {
return (info.Length > 3) ? info[3].Substring(info[3].LastIndexOf('=') + 1) : null;
}
}
public string FullName {
get { return fullName; }
}
public override string ToString()
{
return fullName;
}
public bool Equals(GacAssemblyName other)
{
if (other == null)
return false;
else
return fullName == other.fullName;
}
public override bool Equals(object obj)
{
return Equals(obj as GacAssemblyName);
}
public override int GetHashCode()
{
return fullName.GetHashCode();
}
}
}

17
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ProjectContentRegistry.cs

@ -267,14 +267,21 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -267,14 +267,21 @@ namespace ICSharpCode.SharpDevelop.Dom
if (File.Exists(itemFileName)) {
pc = CecilReader.LoadAssembly(itemFileName, this);
} else {
AssemblyName asmName = GacInterop.FindBestMatchingAssemblyName(itemInclude);
if (asmName != null) {
GacAssemblyName asmName = GacInterop.FindBestMatchingAssemblyName(itemInclude);
if (persistence != null && asmName != null) {
//LoggingService.Debug("Looking up in DOM cache: " + asmName.FullName);
pc = persistence.LoadProjectContentByAssemblyName(asmName.FullName);
}
if (pc == null && asmName != null) {
string subPath = Path.Combine(asmName.Name, GetVersion__Token(asmName));
subPath = Path.Combine(subPath, asmName.Name + ".dll");
foreach (string dir in Directory.GetDirectories(GacInterop.GacRootPath, "GAC*")) {
itemFileName = Path.Combine(dir, subPath);
if (File.Exists(itemFileName)) {
pc = CecilReader.LoadAssembly(itemFileName, this);
if (persistence != null) {
persistence.SaveProjectContent(pc);
}
break;
}
}
@ -287,13 +294,11 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -287,13 +294,11 @@ namespace ICSharpCode.SharpDevelop.Dom
return pc;
}
static string GetVersion__Token(AssemblyName asmName)
static string GetVersion__Token(GacAssemblyName asmName)
{
StringBuilder b = new StringBuilder(asmName.Version.ToString());
b.Append("__");
foreach (byte by in asmName.GetPublicKeyToken()) {
b.Append(by.ToString("x2"));
}
b.Append(asmName.PublicKey);
return b.ToString();
}

22
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ProjectContent/ReflectionProjectContent.cs

@ -9,6 +9,7 @@ using System; @@ -9,6 +9,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Microsoft.Win32;
using ICSharpCode.SharpDevelop.Dom.ReflectionLayer;
@ -84,12 +85,33 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -84,12 +85,33 @@ namespace ICSharpCode.SharpDevelop.Dom
string runtimeDirectory = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
fileName = LookupLocalizedXmlDoc(Path.Combine(runtimeDirectory, Path.GetFileName(assemblyLocation)));
}
if (fileName == null) {
// still not found -> look in WinFX reference directory
string referenceDirectory = WinFXReferenceDirectory;
if (!string.IsNullOrEmpty(referenceDirectory)) {
fileName = LookupLocalizedXmlDoc(Path.Combine(referenceDirectory, Path.GetFileName(assemblyLocation)));
}
}
if (fileName != null && registry.persistence != null) {
this.XmlDoc = XmlDoc.Load(fileName, Path.Combine(registry.persistence.CacheDirectory, "XmlDoc"));
}
}
static string WinFXReferenceDirectory {
get {
RegistryKey k = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup\Windows Communication Foundation");
if (k == null)
return null;
object o = k.GetValue("ReferenceInstallPath");
k.Close();
if (o == null)
return null;
else
return o.ToString();
}
}
public void InitializeSpecialClasses()
{
if (GetClassInternal(VoidClass.VoidName, 0, Language) != null) {

4
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionLoader.cs

@ -21,7 +21,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -21,7 +21,7 @@ namespace ICSharpCode.SharpDevelop.Dom
public static Assembly ReflectionLoadGacAssembly(string partialName, bool reflectionOnly)
{
if (reflectionOnly) {
AssemblyName name = GacInterop.FindBestMatchingAssemblyName(partialName);
GacAssemblyName name = GacInterop.FindBestMatchingAssemblyName(partialName);
if (name == null)
return null;
return Assembly.ReflectionOnlyLoad(name.FullName);
@ -98,7 +98,7 @@ namespace ICSharpCode.SharpDevelop.Dom @@ -98,7 +98,7 @@ namespace ICSharpCode.SharpDevelop.Dom
LoggingService.Warn("AssemblyResolve: ReflectionOnlyLoad failed for " + e.Name);
// We can't get the assembly we want.
// But propably we can get a similar version of it.
AssemblyName fixedName = GacInterop.FindBestMatchingAssemblyName(e.Name);
GacAssemblyName fixedName = GacInterop.FindBestMatchingAssemblyName(e.Name);
LoggingService.Info("AssemblyResolve: FixedName: " + fixedName);
return Assembly.ReflectionOnlyLoad(fixedName.FullName);
}

Loading…
Cancel
Save