How do I specify my own bitmap image in a call to Commands2.AddNamedCommand2?
I'm writing a Visual Studio add-in and have a 16x16 bitmap resource that I would like to use as the button image for my menu item.
Following these instructions from the MSDN, I renamed the resource 1
and the file 1.bmp
, then edited Resources.resx
accordingly:
<data name="1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\1.bmp;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
I then changed my call to Commands2.AddNamedCommand2
, passing false
and 1
as the arguments for MSOButton
and Bitmap
respectively:
Command command = commands.AddNamedCommand2(addIn, "MyAddIn", "MyAddIn", "Open MyAddIn", false, 1, ref contextGUIDS,
(int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
Now when I launch the add-in in Visual Studio, Commands2.AddNamedCommand2
throws a FileNotFoundException
:
Additional information: Could not load file or assembly 'MyAddIn.resources, Version=0.1.3939.33205, Culture=en, PublicKeyTok开发者_如何学Pythonen=null' or one of its dependencies. The system cannot find the file specified.
What am I doing wrong?
EDIT: I'm doing this in Visual Studio 2005, in case that is significant.
EDIT2: The project is on github, if anyone wants to look at the source and/or try to reproduce the issue.
If you create the resource-only assembly manually, e.g.
resgen.exe "Path\To\Resource.resx" "Path\To\Bin\en\MyAddin.resources" al.exe /c:en /embed:"Path\To\Bin\en\MyAddin.resources" /out:"Path\To\Bin\en\MyAddin.resources.dll"
and then set your assembly version to 0.0.0.0 (or alternatively set the resource assembly version in the al.exe command, or use the [assembly: System.Resources.SatelliteContractVersion()]
attribute), you should get past the FileNotFoundException. Using resgen.exe might also tell you why the assembly isn't being generated and linked automatically.
You can also subscribe to the AppDomain.AssemblyResolve
event, e.g. here, to trace or override the loading of resource (or other) assemblies.
精彩评论