Reputation: 1
I am trying to write a VSIX plugin that automates the process of moving files within a visual studio 2017 C++ project. So far I have tried the following, which unfortunately has not worked. The file is moved on disk and the associated VCFile is updated accordingly, however the source control provider (P4V in this particular case) does not check out the file and perform a move automatically as I would expect. I have also tried using the OnQueryRename and OnAfterRename methods of the IVsTrackPRojectDocuments2 service. The problem with this approach is that both of these methods require an IVsProject . I have been unable to figure out how to resolve a reference to an associated IVsProject from the VCProject reference that I have. Any help from someone who knows this area a little more would be greatly appreciated!
// These variables are resolved outside the scope of this method and passed in
string oldFileLocation;
string newFileLocation;
VCProject containingProject;
IVsTrackProjectDocuments3 documentTrackingService = await asyncServiceProvider.GetServiceAsync(typeof(IVsTrackProjectDocuments3)) as IVsTrackProjectDocuments3;
int methodSucceeded = documentTrackingService.HandsOffFiles((uint)__HANDSOFFMODE.HANDSOFFMODE_DeleteAccess, 2, new string[] { oldFileLocation, newFileLocation });
// If the method did not succeed then we cannot continue
if (methodSucceeded != VSConstants.S_OK)
{
return;
}
// Now move the file on disk and update the relative path of the file
await Task.Run(() => { File.Move(oldFileLocation, newFileLocation); });
// Store the old relative path for rollback
string oldRelativePath = movedFile.RelativePath;
movedFile.RelativePath = GetRelativePath(containingProject.ProjectDirectory, newFileLocation);
methodSucceeded = documentTrackingService.HandsOnFiles(2, new string[] { oldFileLocation, newFileLocation });
// If the method did not succeed then we need to roll back
if (methodSucceeded != VSConstants.S_OK)
{
// Now move the file on disk and update the relative path of the file
await Task.Run(() => { File.Move(newFileLocation, oldFileLocation); });
movedFile.RelativePath = oldRelativePath;
}
Upvotes: 0
Views: 58
Reputation: 1
Ok so on further investigation I realised that you can simply call 'AddFile' on the VCFile to trigger a move:
await Task.Run(() => { File.Move(oldFileLocation, newFileLocation); });
movedFile.AddFile(newFileLocation);
Upvotes: 0