Visual Studio Addin not showing - visual-studio-2012

I've created very simple Visual Studio Add-in, ala this article by JP Booodhoo.
http://codebetter.com/jpboodhoo/2007/09/04/macro-to-aid-bdd-test-naming-style/
The addin works in debug, so if I F5 in the add in solution, and open a solution then the addin shows in the tools. However, it doesn't show when not debugging. i.e. after I've deployed the addin, closed and re-opened my solution.
Am I missing something?
In terms of deployment, I followed the deployment steps in this article and deployed it to C:\Users[your user name]\Documents\Visual Studio 2012\Addins
Alternative to macros in Visual Studio 2012
public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
handled = false;
if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
{
if(commandName == "KinghamExtensions.Connect.KinghamExtensions")
{
var selection = (TextSelection)(_applicationObject.ActiveDocument.Selection);
selection.SelectLine();
if (selection.Text == "") return;
var prefix = "public void ";
var index = selection.Text.IndexOf(prefix);
prefix = selection.Text.Substring(0, index) + prefix;
var description = selection.Text.Replace(prefix, String.Empty);
selection.Text = prefix + description.Replace(" ", "_").Replace("'", "_");
selection.LineDown();
selection.EndOfLine();
handled = true;
}
}
}
As I say, the code works when running the addin from vs in debug, but doesn't show in the tools menu.
Also, it doesn't show up in the keyboard options like the Git Extensions addin does meaning I can't assign a key binding.
Any thoughts?

It is hard to answer by the information you given, but at first you should check the followings:
Your AddIn should appear in the Tools>Add-in Managger...
If you set the first check box before it, than it should be loaded.
If it isn't and you get an error message, click to no, else the Studio will rename the deployed .AddIn file.
You should check if your release assembly is at the place referenced by the Assembly element like this: <Assembly>C:\Users[your user name]\Documents\Visual Studio 2012\Projects\MyAddin1\MyAddin1\bin\MyAddin1.dll</Assembly>
in the .AddIn file deployed by Visual Studio to the AddIn folder you mentioned in your question.
If it is, and the error pesrists, you should add some log to your Add-In (a Windows MessageBox will do)
and place it to the OnConnection method. The error can appear either OnConnection throws an Exception while the IDE trying to load it, or the FullClassName element in the AddIn file refers to an other name than your Connection class has.
If you get no errors and your OnConnection runs properly, then it could be an exception thrown while your code is adding your command, - if you do the same way as it is in a generated Add-In template in a try/catch block- and you need to resolve it.

Related

Visual Studio 2022 (C++) "Add Event Handler..." generating bad names

I am working on an MFC application with a Ribbon Bar and am experiencing difficulty adding event handlers for new controls from the Ribbon Designer. This was working fine the last time I edited the Ribbon roughly 2 months ago. For instance, adding a new button ("Test Function") I change the resource ID to "ID_BUTTON_TESTFUNC" then right click the button and select "Add Event Handler...". The dialog comes up with a Function Name "On18" rather than "OnButtonTestfunc" and adds a message map and function that don't respond to the button.
BEGIN_MESSAGE_MAP(CMFCApplication2View, CView)
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CMFCApplication2View::OnFilePrintPreview)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_COMMAND(18, &CMFCApplication2View::On18)
...
void CMFCApplication2View::On18()
{
}
I have tried the following, expecting (hoping) VS would return to normal behavior:
The same process on 2 computers with the same results
Updating Visual Studio to 17.4.4 (from 17.4.3)
Repairing Visual Studio
Creating a new blank MFC application - same results
In Account Options: UNchecking "Syncronize Visual Studio settings across devices and installs..."
Clearing all Visual Studio settings (Tools, Import Export Settings, Reset all settings)
Changed IDE Tools menu -> Options -> Text Editor -> C/C++ -> Advanced -> Rescan Solution Interval = 0 per Alen Wesker post on: Can't add event handler in visual studio 2010 (mfc project)
Manually adding the message map entry, function declaration and function definition works and responds to the button press:
MFCApplication2View.h:
afx_msg void OnButtonTestfunc();
MFCApplication2View.cpp:
ON_COMMAND(ID_BUTTON_TESTFUNC, &CMFCApplication2View::OnButtonTestfunc)
...
void CMFCApplication2View::OnButtonTestfunc()
{
//my code here
}
But I am concerned about what else might be corrupted in VS. Any thoughts would be very welcome.
Microsoft indicates that this is an issue and had been previously fixed in version 17.5 Preview 2. See: https://developercommunity.visualstudio.com/t/MFC-Add-Event-Handler-Dialog--not-prope/10211759.

ReSharper - Document Saved Event For Inactive File in Visual Studio

I’ve set up my own source control plug-in for Visual Studio.
It’s registered with visual studio and can be selected from the list of Source Control plug-ins.
I’ve got no issues with files that are modified from with in Visual Studio as I’m using to catch the event before save:
IVsRunningDocTableEvents3
If the file isn’t loaded as an active document in Visual Studio, I’m having problems detecting that it is about to be edited so I can check it out of Source Control.
I’ve tried using the ReSharper event – DocumentManagerOperations suggested here:
https://resharper-support.jetbrains.com/hc/en-us/community/posts/205991489-Document-Saved-Event
I’m having issues detecting if these types of files need checked out:
.DotSettings. – When saving the ReSharper options settings
csproj – When adding Nuget Packages with ReSharper.
.cs when editing files that are not opened in VS with ReSharper, i.e.
fix naming in project.
Is there an event that’s triggered when a file is edited but not loaded?
Thank you!
I used the interface:
IVsQueryEditQuerySave2
More information here:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.interop.ivsqueryeditquerysave2?view=visualstudiosdk-2017
And made use of:
public int QueryEditFiles(uint rgfQueryEdit, int cFiles, string[] rgpszMkDocuments, uint[] rgrgf,
VSQEQS_FILE_ATTRIBUTE_DATA[] rgFileInfo, out uint pfEditVerdict, out uint prgfMoreInfo)
And:
public int QuerySaveFiles(uint rgfQuerySave, int cFiles, string[] rgpszMkDocuments, uint[] rgrgf,
VSQEQS_FILE_ATTRIBUTE_DATA[] rgFileInfo, out uint pdwQsResult)
something like this:
if (rgfQueryEdit != (uint)tagVSQueryEditFlags.QEF_ReportOnly)
{
if (rgpszMkDocuments != null)
{
foreach (var doc in rgpszMkDocuments)
{
//Do Something
Hope that helps you out.

Visual Studio extension - creating project type

I'm trying to create a new Visual Studio project type following the tutorial:
http://msdn.microsoft.com/en-us/library/vstudio/cc512961.aspx
Unfortunately I'm getting a strange exception stating that "Guid should contain 32 digits and 4 dashes".
The error appears somewhere along the lines:
// Launch the aggregate creation process (we should be called back on our
IVsAggregatableProjectFactoryCorrected implementation)
IVsCreateAggregateProject aggregateProjectFactory =IVsCreateAggregateProject)this.Site.GetService(typeof(SVsCreateAggregateProject));
int hr = aggregateProjectFactory.CreateAggregateProject(guidsList, fileName, location, name, flags, ref projectGuid, out project);
if(hr == VSConstants.E_ABORT)
canceled = 1;
ErrorHandler.ThrowOnFailure(hr);
I 've got no idea what I'm doing wrong and how to debug this. ErrorHandler just throws exception.

WPF Designer throws error when string resources are used in code behind

I have a wpf custom control (in AssemblyA) that references a string resource from an resx file in an external assembly (AssemblyB).
public override void OnApplyTemplate()
{
try
{
base.OnApplyTemplate();
// ...
// Do Stuff
// ...
}
catch (Exception ex)
{
Logger.Error(ExceptionCodes.Ex50000, ex);
}
}
When I add the custom control (in AssemblyA) via a dll reference to a page in another project (AssemblyC) in another solution, the control fails to display in the designer. Instead, the designer displays a nice big red cross with the message
FileNotFoundException: Could not load file or assembly 'AssemblyB'.
The AssemblyB was also added as a dll reference to AssemblyC.
Removing the the references to the string resource in AssemblyA removes the error and allows the control to display correctly in the designer. Unfortunately, this is not an option as the string resources are used throughout the application for support reasons.
Creating an resx file in AssemblyA also removes the error but decentralises the resources which is not an option for on going development.
Based on the above, the designer is obviously not loading the resource assembly. Any insights would be appreciated.
To Summarise
CustomControl in Assembly A in Solution 1 references a string resourced from a resx file in Assembly B in Solution 1. Assembly C in Solution 2 has a dll reference to both Assembly A and Assembly B. A UserControl in Assembly C uses CustomControl in Assembly A. The Visual Studio WPF designer throws a FileNotFound exception when displaying the UserControl.
Let it throw error, just check whether your are able to complie and run, the Make the assembly In Solution C as exe and try to run it. Because with Visual studio 10.0.4, i have see that exception many times, but if it is complied it doesn't give any compiler error, just try to compile and run it

Is it possible to add solution-specific tools to Visual Studio 2012

Can you do something to the .SLN/.CSPROJ files in VS2012 so that when you right-click the solution/project in the Solution Explorer, there would be a new item on the context-menu which runs a tool you specify?
I know you can add custom entries to the Tools menu, but in this case the tools are specific to that particular solution.
You can add buttons to Solution context menu like below from an Add-In:
Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["Solution"];
try
{
//Add a command to the Commands collection:
Command command = commands.AddNamedCommand2(_addInInstance, "MyAddinMenuBar", "MyAddinMenuBar", "Executes the command for MyAddinMenuBar", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
//Add a control for the command to the solution context menu:
if (command != null)
{
command.AddControl(menuBarCommandBar, 1);
}
}
catch (System.ArgumentException)
{
// safely ignore the exception.
}
The specification of tools for different solutions should be handled internally by your Add-In. You can extract the full path of a solution (from _applicationObject.Solution.FullName) also the properties of contained projects (from _applicationObject.Solution.Projects ).
If you are using a VSPackage you should define a vsct file to add the command and the menu item.

Resources