ReSharper - Document Saved Event For Inactive File in Visual Studio - resharper

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.

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.

Why will MFC not load a bitmap resource in single modual (.cpp) VS PROJECT?

I have code that was first developed with Visual C++ Version 1.52 (working and self taught). I am now trying to convert it to a Visual Studio project. It is a single module project written with MFC. I used the 'project from existing code' option to generate the project which executes just fine but for loading bitmap resources. I tested the same relevant code (LoadBitmap and LoadImage) in MFC multi-module projects code and they work just fine. I am able to load bitmap files directly from disk. If I delete the bitmap files from the project there is 22k less size of the code. The total bitmap file size is 18k. The only error message that I get is '_WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)'. I am assuming that the default is adequate. At this point I am thinking that it is a link properties issue because of MFC, but I don't know what that might be. Any ideas? Thank you.
//header
//
class CMainWindow : public CFrameWnd
{
public:
CMainWindow();
//{{AFX_MSG( CMainWindow )
afx_msg void OnPaint();
afx_msg void OnDestroy();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
//protected:
BOOL flag;
BOOL game, turn;
CWnd tictic1, tictic2, tictic3, tictic4, tictic5, tictic6, tictic7, tictic8, tictic9;
CRect RCT;
int id, count;
CBitmap O, X;
//body
//
CMainWindow::CMainWindow()
{
LoadAccelTable("MainAccelTable");
Create(NULL, "Tic Tac Toe\0",
WS_OVERLAPPEDWINDOW, rectDefault, NULL, NULL, 0, NULL);
flag = TRUE;
id = 0;
O.LoadBitmap(IDB_BITMAP1);
X.LoadBitmap(IDB_BITMAP2);
If I transplant the relevant code into VS generated MFC documents it works. The only difference is that all of my code is original Visual C++ Version 1.52 MFC code, in a single .cpp document but all the rest of the code seems to work fine.
Uh, when I has collecting observations for this query, I deleted the two relevant bitmap files from the resources in order the report the difference in file size. After I added them back in, the functions then work properly. I think that what I had originally done was when first importing the new resources, I tried selecting the two as a group and when they displayed right, in the resource file, I assumed that it had worked. It apparently didn't. Duh!
Uh, development; after cleaning up my code, I rebuilt it and it wouldn't load bitmap resources. I deleted the resources then installed them again and the program has worked since. So you tell me. I think that it's serendipitous. Duh!

T4 template shadow copy does not work

I'm using VS2012 and T4 templates and assemblies are supposed to be shadow copied, meaning that you can reference an assembly in a template and then recompile that assembly. But this simply doesn't work for me. When I try it, when I try to rebuild the assembly, I get errors like:
Unable to copy file "obj\Debug\xxx.dll" to "..\bin\xxx.dll".
The process cannot access the file '..\bin\xxx.dll' because it is being used by another process.
The only way around it is to restart Visual Studio, and this is so tedious that I'm ready to abandon T4 entirely. What could I be doing wrong?
So this isn't really an answer yet but hopefully we get there
Test ran the following in VS2013 (I realize you run VS2012)
<## assembly name = "$(SolutionDir)\TestProj\bin\Debug\TestProj.dll"#>
<## import namespace = "TestProj"#>
namespace ConsoleApplication1
{
class <#=Testing.Name#>
{
}
}
The TestProj contains the Testing class
namespace TestProj
{
public static class Testing
{
public static string Name
{
get { return "Tester" ;}
}
}
}
This did work very well in VS2013 and as far as I remember this worked in VS2012 as well.I will try to install VS2012 on one of my machines but do you mind testing this simple sample on your installation to validate it's not something in your solution that holds the dll?
In case you are interested in the project file you can find it here:
https://github.com/mrange/CodeStack/tree/master/q21118821
I work around similar issue. T4 design time template is processed in different App domain under the same process of visual studio. When rebuild the solution Visual Studio tries to replace the referenced DLL, and it cannot replace it because it is still in use.
I work around this issue by deleting the AppDomain in which T4 template is processed. See msdn

Visual Studio Addin not showing

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.

What are these odd files added to my Visual Studio MFC project?

I have a visual studio solution where one of the projects has somehow acquired several .bin files. They are named bin00001.bin, bin00002.bin, etc... and contains some kind of registry information. The contents of these files are one section repeated a number of times.
bin00001.bin:
HKCR
{
NoRemove AppID
{
'%APPID%' = s 'ApplicationName'
'ApplicationName.EXE'
{
val AppID = s '%APPID%'
}
}
}
HKCR
{
NoRemove AppID
{
'%APPID%' = s 'ApplicationName'
'ApplicationName.EXE'
{
val AppID = s '%APPID%'
}
}
}
This file had two copies of this section and the other files has. Note that a similar file applicat.bin seems to be the original file with one such section and I guess that it needs to be there.
What are these and why are there so many of them and why are they spread over so many files?
they are referenced in the .rc file and are designated resource identifiers in resource.h. I'm also pretty sure it generated a few of them when I added a couple of ATL classes. (I should maybe mention that this is an MFC project!) I'll add the tag
Update
I should maybe add that the executable contains a COM type library. Would this have anything to do with COM registration?
I figured it out what they are.
Those .bin are replicas of the ApplicationName.rgs file.
I still don't know why Visual Studio created them in the first place though. Some kind of backup, I guess..?

Resources