diff --git a/ILSpy.AddIn/Commands/OpenILSpyCommand.cs b/ILSpy.AddIn/Commands/OpenILSpyCommand.cs index ce1802086..37d4024d1 100644 --- a/ILSpy.AddIn/Commands/OpenILSpyCommand.cs +++ b/ILSpy.AddIn/Commands/OpenILSpyCommand.cs @@ -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 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 diff --git a/ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs b/ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs index 25751f7f6..699b54d7e 100644 --- a/ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs +++ b/ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs @@ -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 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) diff --git a/ILSpy.AddIn/Commands/OpenReferenceCommand.cs b/ILSpy.AddIn/Commands/OpenReferenceCommand.cs index 5c5318f8c..099b23f3d 100644 --- a/ILSpy.AddIn/Commands/OpenReferenceCommand.cs +++ b/ILSpy.AddIn/Commands/OpenReferenceCommand.cs @@ -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 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 GetReferences(Microsoft.CodeAnalysis.Project roslynProject) + private Dictionary GetReferences(Microsoft.CodeAnalysis.Project parentProject) { var dict = new Dictionary(); - 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 } } } - 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().FirstOrDefault(p => p.FileName == roslynProject.FilePath); + if (roslynProject != null && project != null) + dict.Add(roslynProject.AssemblyName, GetProjectOutputPath(project, roslynProject)); } return dict; }