C# 如何在VisualStudioSDK中移动文档并确保通知所有源代码管理提供程序 我试图编写一个VS6插件,它可以自动处理VisualStudio 2017 C++项目中的文件移动过程。到目前为止,我已经尝试了以下方法,但不幸的是没有成功。文件在磁盘上移动,相关的VCFile也会相应地更新,但是源代码管理提供程序(本例中为P4V)不会像我预期的那样签出文件并自动执行移动。 我还尝试使用IVsTrackPRojectDocuments2服务的OnQueryRename和OnAfterRename方法。这种方法的问题在于,这两种方法都需要一个IVS项目。我无法从我拥有的VCProject引用中找出如何解析对关联IVsProject的引用。任何人谁知道这个领域多一点的帮助将不胜感激 // 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; }

C# 如何在VisualStudioSDK中移动文档并确保通知所有源代码管理提供程序 我试图编写一个VS6插件,它可以自动处理VisualStudio 2017 C++项目中的文件移动过程。到目前为止,我已经尝试了以下方法,但不幸的是没有成功。文件在磁盘上移动,相关的VCFile也会相应地更新,但是源代码管理提供程序(本例中为P4V)不会像我预期的那样签出文件并自动执行移动。 我还尝试使用IVsTrackPRojectDocuments2服务的OnQueryRename和OnAfterRename方法。这种方法的问题在于,这两种方法都需要一个IVS项目。我无法从我拥有的VCProject引用中找出如何解析对关联IVsProject的引用。任何人谁知道这个领域多一点的帮助将不胜感激 // 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; },c#,visual-c++,version-control,vsix,visual-studio-sdk,C#,Visual C++,Version Control,Vsix,Visual Studio Sdk,好的,在进一步的调查中,我意识到你可以简单地调用VCFile上的“AddFile”来触发移动: await Task.Run(() => { File.Move(oldFileLocation, newFileLocation); }); movedFile.AddFile(newFileLocation);

好的,在进一步的调查中,我意识到你可以简单地调用VCFile上的“AddFile”来触发移动:

await Task.Run(() => { File.Move(oldFileLocation, newFileLocation); });
movedFile.AddFile(newFileLocation);