diff --git a/ILSpy.AddIn/Commands/AssemblyReferenceForILSpy.cs b/ILSpy.AddIn/Commands/AssemblyReferenceForILSpy.cs
new file mode 100644
index 000000000..cde4f679a
--- /dev/null
+++ b/ILSpy.AddIn/Commands/AssemblyReferenceForILSpy.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using VSLangProj;
+
+namespace ICSharpCode.ILSpy.AddIn.Commands
+{
+ ///
+ /// Represents an assembly reference item in Solution Explorer, which can be opened in ILSpy.
+ ///
+ class AssemblyReferenceForILSpy
+ {
+ Reference reference;
+
+ AssemblyReferenceForILSpy(Reference reference)
+ {
+ this.reference = reference;
+ }
+
+ ///
+ /// Detects whether the given selected item represents a supported project.
+ ///
+ /// Data object of selected item to check.
+ /// instance or null, if item is not a supported project.
+ public static AssemblyReferenceForILSpy Detect(object itemData)
+ {
+ return (itemData is Reference reference) ? new AssemblyReferenceForILSpy(reference) : null;
+ }
+
+ ///
+ /// If possible retrieves parameters to use for launching ILSpy instance.
+ ///
+ /// List of current project's references.
+ /// Parameters object or null, if not applicable.
+ public ILSpyParameters GetILSpyParameters(Dictionary projectReferences)
+ {
+ if (projectReferences.TryGetValue(reference.Name, out var path))
+ return new ILSpyParameters(new[] { path });
+
+ return null;
+ }
+ }
+}
diff --git a/ILSpy.AddIn/Commands/NuGetReferenceForILSpy.cs b/ILSpy.AddIn/Commands/NuGetReferenceForILSpy.cs
new file mode 100644
index 000000000..bcbaa82a3
--- /dev/null
+++ b/ILSpy.AddIn/Commands/NuGetReferenceForILSpy.cs
@@ -0,0 +1,53 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using EnvDTE;
+
+namespace ICSharpCode.ILSpy.AddIn.Commands
+{
+ ///
+ /// Represents a NuGet package item in Solution Explorer, which can be opened in ILSpy.
+ ///
+ class NuGetReferenceForILSpy
+ {
+ ProjectItem projectItem;
+
+ NuGetReferenceForILSpy(ProjectItem projectItem)
+ {
+ this.projectItem = projectItem;
+ }
+
+ ///
+ /// Detects whether the given selected item represents a supported project.
+ ///
+ /// Data object of selected item to check.
+ /// instance or null, if item is not a supported project.
+ public static NuGetReferenceForILSpy Detect(object itemData)
+ {
+ if (itemData is ProjectItem projectItem) {
+ var properties = Utils.GetProperties(projectItem.Properties, "Type");
+ if ((properties[0] as string) == "Package") {
+ return new NuGetReferenceForILSpy(projectItem);
+ }
+ }
+
+ return null;
+ }
+
+ ///
+ /// If possible retrieves parameters to use for launching ILSpy instance.
+ ///
+ /// Parameters object or null, if not applicable.
+ public ILSpyParameters GetILSpyParameters()
+ {
+ var properties = Utils.GetProperties(projectItem.Properties, "Name", "Version", "Path");
+ if (properties[0] != null && properties[1] != null && properties[2] != null) {
+ return new ILSpyParameters(new[] { $"{properties[2]}\\{properties[0]}.{properties[1]}.nupkg" });
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/ILSpy.AddIn/Commands/OpenCodeItemCommand.cs b/ILSpy.AddIn/Commands/OpenCodeItemCommand.cs
index 30bca416e..9db92cdf9 100644
--- a/ILSpy.AddIn/Commands/OpenCodeItemCommand.cs
+++ b/ILSpy.AddIn/Commands/OpenCodeItemCommand.cs
@@ -47,7 +47,7 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
if (symbol == null)
return;
var refs = GetReferences(roslynDocument.Project).Select(fn => fn.Value).Where(f => File.Exists(f)).ToArray();
- OpenAssembliesInILSpy(refs, "/navigateTo:" + symbol.GetDocumentationCommentId());
+ OpenAssembliesInILSpy(new ILSpyParameters(refs, "/navigateTo:" + symbol.GetDocumentationCommentId()));
}
internal static void Register(ILSpyAddInPackage owner)
diff --git a/ILSpy.AddIn/Commands/OpenILSpyCommand.cs b/ILSpy.AddIn/Commands/OpenILSpyCommand.cs
index 9d44d1b7d..d3e1254f1 100644
--- a/ILSpy.AddIn/Commands/OpenILSpyCommand.cs
+++ b/ILSpy.AddIn/Commands/OpenILSpyCommand.cs
@@ -11,6 +11,18 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.AddIn.Commands
{
+ public class ILSpyParameters
+ {
+ public ILSpyParameters(IEnumerable assemblyFileNames, params string[] arguments)
+ {
+ this.AssemblyFileNames = assemblyFileNames;
+ this.Arguments = arguments;
+ }
+
+ public IEnumerable AssemblyFileNames { get; private set; }
+ public string[] Arguments { get; private set; }
+ }
+
abstract class ILSpyCommand
{
protected ILSpyAddInPackage owner;
@@ -36,18 +48,21 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
return Path.Combine(basePath, "ILSpy.exe");
}
- protected void OpenAssembliesInILSpy(IEnumerable assemblyFileNames, params string[] arguments)
+ protected void OpenAssembliesInILSpy(ILSpyParameters parameters)
{
- foreach (string assemblyFileName in assemblyFileNames) {
+ if (parameters == null)
+ return;
+
+ foreach (string assemblyFileName in parameters.AssemblyFileNames) {
if (!File.Exists(assemblyFileName)) {
owner.ShowMessage("Could not find assembly '{0}', please ensure the project and all references were built correctly!", assemblyFileName);
return;
}
}
- string commandLineArguments = Utils.ArgumentArrayToCommandLine(assemblyFileNames.ToArray());
- if (arguments != null) {
- commandLineArguments = string.Concat(commandLineArguments, " ", Utils.ArgumentArrayToCommandLine(arguments));
+ string commandLineArguments = Utils.ArgumentArrayToCommandLine(parameters.AssemblyFileNames.ToArray());
+ if (parameters.Arguments != null) {
+ commandLineArguments = string.Concat(commandLineArguments, " ", Utils.ArgumentArrayToCommandLine(parameters.Arguments));
}
System.Diagnostics.Process.Start(GetILSpyPath(), commandLineArguments);
diff --git a/ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs b/ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs
index 699b54d7e..a2f23957a 100644
--- a/ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs
+++ b/ILSpy.AddIn/Commands/OpenProjectOutputCommand.cs
@@ -15,16 +15,12 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
protected override void OnExecute(object sender, EventArgs e)
{
- 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);
- 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) });
+ if (owner.DTE.SelectedItems.Count != 1)
+ return;
+ var projectItemWrapper = ProjectItemForILSpy.Detect(owner.DTE.SelectedItems.Item(1));
+ if (projectItemWrapper != null) {
+ OpenAssembliesInILSpy(projectItemWrapper.GetILSpyParameters(owner));
+ }
}
internal static void Register(ILSpyAddInPackage owner)
diff --git a/ILSpy.AddIn/Commands/OpenReferenceCommand.cs b/ILSpy.AddIn/Commands/OpenReferenceCommand.cs
index d9cb95981..f3c2fcc00 100644
--- a/ILSpy.AddIn/Commands/OpenReferenceCommand.cs
+++ b/ILSpy.AddIn/Commands/OpenReferenceCommand.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using EnvDTE;
using Microsoft.CodeAnalysis;
+using Microsoft.VisualStudio.Shell;
using Mono.Cecil;
using VSLangProj;
@@ -17,109 +18,70 @@ namespace ICSharpCode.ILSpy.AddIn.Commands
{
}
+ protected override void OnBeforeQueryStatus(object sender, EventArgs e)
+ {
+ if (sender is OleMenuCommand menuItem) {
+ menuItem.Visible = false;
+
+ var selectedItemData = owner.GetSelectedItemsData