I'm running the VSShell 2010 and my project is based off the MPF2010 package that's available on the CodePlex.
Recently, I had an issue land on my desk where one of my project files is not saving correctly. I've done some initial investigation, and it looks like the Hierarchy object for this one file is messed up. Steps from the user:
- Open solution
- Close Solution (via File->Close Solution Menu item)
- Open Solution again
- Add file to proj
- Save All
- Check proj file (via notepad), and the added file is not there. (and it's not there if you close and re-open the solution again)
- Exit completely, and it works just fine unless the user closes and opens the solution again.
I found that when the solution is closed, it's not releasing the RDT entry for that project file. Which is resulting the the Hierarchy object to have the wrong cookie, which is causing the save to not work correctly when IVsSolution.SaveSolutionElement(options,
hierarchy, docCookie) is called on the proj file, when the file is added...
I found this by registering and checking RDT in the IVsSolutionEvents3.OnAfterCloseSolution (pardon the code, it's rough, but I was just playing around):
public override int OnAfterCloseSolution(object reserved)
{
IVsRunningDocumentTable rdtService = (IVsRunningDocumentTable)Package.GetGlobalService(typeof(SVsRunningDocumentTable));
IVsRunningDocumentTable2 rdtService2 = (IVsRunningDocumentTable2)Package.GetGlobalService(typeof(SVsRunningDocumentTable));
if (rdtService == null)
{
throw new System.InvalidOperationException("Could not get the RDT Service");
}
IEnumRunningDocuments ppenum;
rdtService.GetRunningDocumentsEnum(out ppenum);
uint[] cookie = new uint[1];
uint numFetched;
while (ppenum.Next(1, cookie, out numFetched) == VSConstants.S_OK)
{
uint pgrfRDTFlags;
uint pdwReadLocks;
uint pdwEditLocks;
string pbstrMkDocument;
IVsHierarchy ppHier;
uint pitemid;
IntPtr ppunkDocData;
rdtService.GetDocumentInfo(
cookie[0],
out pgrfRDTFlags,
out pdwReadLocks,
out pdwEditLocks,
out pbstrMkDocument,
out ppHier,
out pitemid,
out ppunkDocData
);
rdtService2.CloseDocuments((uint)__FRAMECLOSE.FRAMECLOSE_NoSave, null, cookie[0]);
}
return VSConstants.S_OK;
}I've attempted to use the RDT to close the document when this condition occurs (I don't want to do this, and it doesn't work anyways). I can see that the document is not being closed successfully since if I open a completely different solution, and
when it closes the RDT still reports the first proj file as being open.
Any suggestions on why the RDT would not close a proj file, or be unable to close a document when a Solution is closed?
Note: There are multiple proj files in the solution, it's only the 1 that is not closing.