Skip to content

Commit

Permalink
Add menu command for Go To Defnition - Native
Browse files Browse the repository at this point in the history
This commit contains the bare minimum changes
necessary to make the menu item show up.  The
implementation will come in the next commit.
  • Loading branch information
SLaks committed Aug 27, 2014
1 parent a71bd37 commit 6ce75a4
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Ref12/Ref12.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<AssemblyName>Ref12</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<GeneratePkgDefFile>false</GeneratePkgDefFile>
<ReferencePath>$(ReferencePath);$(MSBuildThisFileDirectory)..\References\v10.0</ReferencePath>
<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)\devenv.exe</StartProgram>
Expand Down Expand Up @@ -104,6 +103,7 @@
<Compile Include="Commands\TextViewListener.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Ref12Package.cs" />
<Compile Include="RoslynUtilities.cs" />
<Compile Include="Services\ILogger.cs" />
<Compile Include="Services\CSharp12Resolver.cs" />
Expand All @@ -119,6 +119,13 @@
</None>
</ItemGroup>
<ItemGroup>
<VSCTCompile Include="Ref12.vsct">
<ResourceName>Menus.ctmenu</ResourceName>
</VSCTCompile>
<EmbeddedResource Include="VSPackage.resx">
<MergeWithCTO>true</MergeWithCTO>
<ManifestResourceName>VSPackage</ManifestResourceName>
</EmbeddedResource>
<Content Include="Resources\Ref12-200.png">
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
Expand All @@ -136,6 +143,9 @@
<Name>Ref12.Unversioned</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<UseCodebase>true</UseCodebase>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
25 changes: 25 additions & 0 deletions Ref12/Ref12.vsct
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<Extern href="stdidcmd.h"/>
<Extern href="vsshlids.h"/>
<Commands package="PackageGuid">
<Buttons>
<Button guid="CommandsGuid" id="GoToNativeDefinition" priority="0x0101" type="Button">
<Parent guid="guidSHLMainMenu" id="IDG_VS_CODEWIN_NAVIGATETOLOCATION"/>
<Icon guid="guidObjectBrowserButtons" id="15"/>

<Strings>
<ButtonText>Go To Definition - &amp;Native</ButtonText>
</Strings>
</Button>
</Buttons>
</Commands>

<Symbols>
<GuidSymbol name="PackageGuid" value="{7E85FEAF-1785-4BE8-8E0C-0B4C55A97851}" />

<GuidSymbol name="CommandsGuid" value="{BD27207E-0A63-4C87-A111-D226F1C22EE3}">
<IDSymbol name="GoToNativeDefinition" value="0" />
</GuidSymbol>
</Symbols>
</CommandTable>
17 changes: 17 additions & 0 deletions Ref12/Ref12Package.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell;

namespace SLaks.Ref12 {
// These GUIDS and command IDs must match the VSCT.
[ProvideMenuResource("Menus.ctmenu", 1)]
[Guid("7E85FEAF-1785-4BE8-8E0C-0B4C55A97851")]
[PackageRegistration(UseManagedResourcesOnly = true)]
class Ref12Package : Package {
}

[Guid("BD27207E-0A63-4C87-A111-D226F1C22EE3")]
enum Ref12Command {
GoToDefinitionNative = 0
}
}
101 changes: 101 additions & 0 deletions Ref12/VSPackage.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
1 change: 1 addition & 0 deletions Ref12/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
</Identifier>
<Content>
<MefComponent>|%CurrentProject%|</MefComponent>
<VsPackage>|%CurrentProject%;PkgdefProjectOutputGroup|</VsPackage>
</Content>
</Vsix>

15 comments on commit 6ce75a4

@paul1956
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this been updated for VS 2015, the 2015 vsixmanifest file looks nothing like this example, at least for VB.

@SLaks
Copy link
Owner Author

@SLaks SLaks commented on 6ce75a4 Sep 21, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?
I published this to the gallery a while ago.

Note that my extensions use VSIX v1, for compatibility with VS2010.

@paul1956
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to follow it for VS2015 using Visual Basic and can't map the instructions but I don't think it is because I am using VB.. The vsixmanifest file does not have entries (Identifier, Content, MefComponent). from your example.

@SLaks
Copy link
Owner Author

@SLaks SLaks commented on 6ce75a4 Sep 21, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean you're trying to add a menu command to a MEF-only VSIX?

You're having trouble because I'm using VSIX v1, whereas you're probably using VSIX v2 (the language is completely irrelevant).
You should be able to add the VsPackage / Pkgdef content from the VSIX v2 designer; IIRC, it's one of the entries in the dropdown.

@paul1956
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to add a menu to an Analyzer that is delivered through a VSIX. The VSIX file references a VB project in the some Solution. Don't know what "VSIX v2 designer; IIRC" is but I think you are saying that I can add a "menu item" to Visual Studio 2015 directly within Visual Studio without manually editing. I did try to add a "Command Item" directly to the VXIS project, but got over 300 errors just from adding the item which lead me to your post looking for an example..

@SLaks
Copy link
Owner Author

@SLaks SLaks commented on 6ce75a4 Sep 21, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show me your VSIX manifest.

The non-code changes in this commit (VSIX manifest and GeneratePkgDefFile) do not affect compilation; they're just necessary to get VS to actually load the menu item.

If you 're getting compilation errors, you're probably missing some assembly references.
What errors are you getting?

Other than the differences between a v2 VSIX and a v1 VSIX, you should do exactly what I did in this commit, and that should make a menu item appear.

@paul1956
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual it is 381 warnings in ControlName.vb, ControlNamePackage.vb that were added to the VSIX project. The warnings are "Type or namespace definition or end-of-line expected", "Newline in Comment", "Type Expected" , "Too many characters in character literal"., "Comma Expected". None of which make any sense in a VB file. If I move these files to a VB project most of the errors disappear and the ones that are left are all correct..

<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
  <Metadata>
    <Identity Id="Pure_Visual_Basic_Refactoring.Vsix..ac920cbf-a241-4baa-a5d7-5b3b8661ecb9" Version="1.0" Language="en-US" Publisher="Paul M Cohen" />
    <DisplayName>Pure Visual Basic Refactoring</DisplayName>
    <Description xml:space="preserve">This is a Code Refactoring and Analyzer written in Visual Basic by Paul M Cohen</Description>
    <License>LICENSE.txt</License>
    <Icon>ms_visual_basic_express.png</Icon>
    <Tags>Refactoring, code analysis, analyzer, Roslyn, VB.NET</Tags>
  </Metadata>
  <Installation>
    <InstallationTarget Version="[14.0,]" Id="Microsoft.VisualStudio.Pro" />
    <InstallationTarget Version="[14.0,]" Id="Microsoft.VisualStudio.VSWinDesktopExpress" />
    <InstallationTarget Version="[14.0,]" Id="Microsoft.VisualStudio.VWDExpress" />
    <InstallationTarget Version="[14.0,]" Id="Microsoft.VisualStudio.VSWinExpress" />
  </Installation>
  <Dependencies>
    <Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5.2,)" />
    <Dependency Id="Microsoft.VisualStudio.MPF.14.0" DisplayName="Visual Studio MPF 14.0" d:Source="Installed" Version="[14.0]" />
  </Dependencies>
  <Assets>
    <Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="Pure_Visual_Basic_Refactoring" Path="|Pure_Visual_Basic_Refactoring|" />
    <Asset Type="Microsoft.VisualStudio.Analyzer" d:Source="Project" d:ProjectName="Pure_Visual_Basic_Refactoring" Path="|Pure_Visual_Basic_Refactoring|" />
    <Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
  </Assets>
</PackageManifest>

@SLaks
Copy link
Owner Author

@SLaks SLaks commented on 6ce75a4 Sep 21, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Asset Type="Microsoft.VisualStudio.VsPackage is exactly what you need.

It sounds like you're adding a VB file to a C# project.
Change your project type.

@paul1956
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VSIX project includies the line below but I have never seen this line is a VB Project file and all the errors match exactly what you would get if you add the VB files in a C# project and rename them to .cs.

@paul1956
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have nothing in C# but something is assuming that files in a VSIX project are C# even if they have a .VB extension. How to I change a project type for something that Visual Studio created automatically. If I include the two fines in a C# project I actually don't get the errors and Visual Studio seems to understand they are VB (I didn't try to actual compile).

@paul1956
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I need to Address this with the Roslyn team or Visual Studio support.

@SLaks
Copy link
Owner Author

@SLaks SLaks commented on 6ce75a4 Sep 21, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VSIX projects are normal VS projects that have a few extra files & build targets.

You can change the language by changing the project GUID near the type of the file; search Google to find a list of VS project GUIDs.

@paul1956
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    <ProjectTypeGuids>{82b43b9b-a64c-4715-b499-d71e9ca2bd60};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>

which translates to Extensibility,VB.NET which is correct but something thinks the 2 VB files are C#

The vsct file includes "C++" .h files and the comment says it is (usually) the C++ preprocessor don't know if that matters.

@SLaks
Copy link
Owner Author

@SLaks SLaks commented on 6ce75a4 Sep 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The VSCT is completely separate from all normal compilation.
Create a new VB VSIX project and compare the project files.
Also, make sure your project is a vbproj and not a csproj.

@paul1956
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new VB extension project added a Menu Item and get identical errors. I filed it with details under Roslyn project.

Please sign in to comment.