Browse Source

Fix some more bugs in ILSpy.AddIn

pull/1108/head
Siegfried Pammer 8 years ago
parent
commit
cf9d803f5d
  1. 12
      ILSpy.AddIn/Commands/OpenILSpyCommand.cs
  2. 9
      ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs
  3. 16
      ILSpy.AddIn/Commands/OpenReferenceCommand.cs

12
ILSpy.AddIn/Commands/OpenILSpyCommand.cs

@ -40,6 +40,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
foreach (string assemblyFileName in assemblyFileNames) { foreach (string assemblyFileName in assemblyFileNames) {
if (!File.Exists(assemblyFileName)) { if (!File.Exists(assemblyFileName)) {
owner.ShowMessage("Could not find assembly '{0}', please ensure the project and all references were built correctly!", assemblyFileName); owner.ShowMessage("Could not find assembly '{0}', please ensure the project and all references were built correctly!", assemblyFileName);
return;
} }
} }
@ -50,6 +51,17 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
System.Diagnostics.Process.Start(GetILSpyPath(), commandLineArguments); System.Diagnostics.Process.Start(GetILSpyPath(), commandLineArguments);
} }
protected string GetProjectOutputPath(EnvDTE.Project project, Microsoft.CodeAnalysis.Project roslynProject)
{
string outputFileName = Path.GetFileName(roslynProject.OutputFilePath);
//get the directory path based on the project file.
string projectPath = Path.GetDirectoryName(project.FullName);
//get the output path based on the active configuration
string projectOutputPath = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString();
//combine the project path and output path to get the bin path
return Path.Combine(projectPath, projectOutputPath, outputFileName);
}
} }
class OpenILSpyCommand : ILSpyCommand class OpenILSpyCommand : ILSpyCommand

9
ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs

@ -1,4 +1,5 @@
using System; using System;
using System.IO;
using System.Linq; using System.Linq;
namespace ICSharpCode.ILSpy.AddIn.Commands namespace ICSharpCode.ILSpy.AddIn.Commands
@ -17,7 +18,13 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
if (owner.DTE.SelectedItems.Count != 1) return; if (owner.DTE.SelectedItems.Count != 1) return;
var project = owner.DTE.SelectedItems.Item(1).Project; var project = owner.DTE.SelectedItems.Item(1).Project;
var roslynProject = owner.Workspace.CurrentSolution.Projects.FirstOrDefault(p => p.FilePath == project.FileName); var roslynProject = owner.Workspace.CurrentSolution.Projects.FirstOrDefault(p => p.FilePath == project.FileName);
OpenAssembliesInILSpy(new[] { roslynProject.OutputFilePath }); string outputFileName = Path.GetFileName(roslynProject.OutputFilePath);
//get the directory path based on the project file.
string projectPath = Path.GetDirectoryName(project.FullName);
//get the output path based on the active configuration
string projectOutputPath = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString();
//combine the project path and output path to get the bin path
OpenAssembliesInILSpy(new[] { Path.Combine(projectPath, projectOutputPath, outputFileName) });
} }
internal static void Register(ILSpyAddInPackage owner) internal static void Register(ILSpyAddInPackage owner)

16
ILSpy.AddIn/Commands/OpenReferenceCommand.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
if (references.TryGetValue(reference.Name, out var path)) if (references.TryGetValue(reference.Name, out var path))
OpenAssembliesInILSpy(new[] { path }); OpenAssembliesInILSpy(new[] { path });
else else
owner.ShowMessage("Could not find reference '{0}'.", reference.Name); owner.ShowMessage("Could not find reference '{0}', please ensure the project and all references were built correctly!", reference.Name);
} else { } else {
dynamic referenceObject = item.Object; dynamic referenceObject = item.Object;
var values = GetProperties(referenceObject.Properties, "Type", "FusionName", "ResolvedPath"); var values = GetProperties(referenceObject.Properties, "Type", "FusionName", "ResolvedPath");
@ -47,14 +47,14 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
OpenAssembliesInILSpy(new string[] { GacInterop.FindAssemblyInNetGac(AssemblyNameReference.Parse(values[1])) }); OpenAssembliesInILSpy(new string[] { GacInterop.FindAssemblyInNetGac(AssemblyNameReference.Parse(values[1])) });
return; return;
} }
owner.ShowMessage("Could not find reference '{0}'.", referenceObject.Name); owner.ShowMessage("Could not find reference '{0}', please ensure the project and all references were built correctly!", referenceObject.Name);
} }
} }
private Dictionary<string, string> GetReferences(Microsoft.CodeAnalysis.Project roslynProject) private Dictionary<string, string> GetReferences(Microsoft.CodeAnalysis.Project parentProject)
{ {
var dict = new Dictionary<string, string>(); var dict = new Dictionary<string, string>();
foreach (var reference in roslynProject.MetadataReferences) { foreach (var reference in parentProject.MetadataReferences) {
using (var assemblyDef = AssemblyDefinition.ReadAssembly(reference.Display)) { using (var assemblyDef = AssemblyDefinition.ReadAssembly(reference.Display)) {
if (IsReferenceAssembly(assemblyDef)) { if (IsReferenceAssembly(assemblyDef)) {
dict.Add(assemblyDef.Name.Name, GacInterop.FindAssemblyInNetGac(assemblyDef.Name)); dict.Add(assemblyDef.Name.Name, GacInterop.FindAssemblyInNetGac(assemblyDef.Name));
@ -63,9 +63,11 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
} }
} }
} }
foreach (var projectReference in roslynProject.ProjectReferences) { foreach (var projectReference in parentProject.ProjectReferences) {
var project = owner.Workspace.CurrentSolution.GetProject(projectReference.ProjectId); var roslynProject = owner.Workspace.CurrentSolution.GetProject(projectReference.ProjectId);
dict.Add(project.AssemblyName, project.OutputFilePath); var project = owner.DTE.Solution.Projects.OfType<EnvDTE.Project>().FirstOrDefault(p => p.FileName == roslynProject.FilePath);
if (roslynProject != null && project != null)
dict.Add(roslynProject.AssemblyName, GetProjectOutputPath(project, roslynProject));
} }
return dict; return dict;
} }

Loading…
Cancel
Save