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 @@ -40,6 +40,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
foreach (string assemblyFileName in assemblyFileNames) {
if (!File.Exists(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 @@ -50,6 +51,17 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
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

9
ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
namespace ICSharpCode.ILSpy.AddIn.Commands
@ -17,7 +18,13 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -17,7 +18,13 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
if (owner.DTE.SelectedItems.Count != 1) return;
var project = owner.DTE.SelectedItems.Item(1).Project;
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)

16
ILSpy.AddIn/Commands/OpenReferenceCommand.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -30,7 +30,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
if (references.TryGetValue(reference.Name, out var path))
OpenAssembliesInILSpy(new[] { path });
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 {
dynamic referenceObject = item.Object;
var values = GetProperties(referenceObject.Properties, "Type", "FusionName", "ResolvedPath");
@ -47,14 +47,14 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -47,14 +47,14 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
OpenAssembliesInILSpy(new string[] { GacInterop.FindAssemblyInNetGac(AssemblyNameReference.Parse(values[1])) });
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>();
foreach (var reference in roslynProject.MetadataReferences) {
foreach (var reference in parentProject.MetadataReferences) {
using (var assemblyDef = AssemblyDefinition.ReadAssembly(reference.Display)) {
if (IsReferenceAssembly(assemblyDef)) {
dict.Add(assemblyDef.Name.Name, GacInterop.FindAssemblyInNetGac(assemblyDef.Name));
@ -63,9 +63,11 @@ namespace ICSharpCode.ILSpy.AddIn.Commands @@ -63,9 +63,11 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
}
}
}
foreach (var projectReference in roslynProject.ProjectReferences) {
var project = owner.Workspace.CurrentSolution.GetProject(projectReference.ProjectId);
dict.Add(project.AssemblyName, project.OutputFilePath);
foreach (var projectReference in parentProject.ProjectReferences) {
var roslynProject = owner.Workspace.CurrentSolution.GetProject(projectReference.ProjectId);
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;
}

Loading…
Cancel
Save