Git 在 Visual Studio 2017 年非常慢

Git in Visual Studio 2017 is extremely slow

我进行了基本检查,例如网络驱动器上没有文件夹、更改某些 git 配置设置、使用不同的存储库、反病毒扫描等。

到目前为止,我知道问题与我的 Windows 帐户无关。在另一台设备上,切换 b运行ches 只需要几秒钟,而不是一分钟。我们注意到 慢速 PC 上的网络流量增加了很多。

当我运行Visual Studio处于安全模式时,

devenv.exe /SafeMode

我立即在 Team Explorer 中看到以下错误:

System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(Int32 hr, Int32[] expectedHRFailure)
   at Microsoft.TeamFoundation.Git.Provider.ServiceProviderExtensionMethods.EnsurePackageLoaded(IServiceProvider serviceProvider, Guid packageGuid)
   at Microsoft.TeamFoundation.Git.Provider.ServiceProviderExtensionMethods.EnsureSccAndTfPackagesLoaded(IServiceProvider serviceProvider)
   at Microsoft.TeamFoundation.Git.Provider.Repositories.GitTeamProjectExtendedInfoProvider.set_ServiceProvider(IServiceProvider value)
   at Microsoft.VisualStudio.TeamFoundation.TeamExplorer.ConnectPage.ConnectPageVS.Initialize(Object sender, PageInitializeEventArgs e)
   at Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.Framework.TeamExplorerPageHost.Initialize(TeamExplorerPageContext context)

根据 msdn 上的建议,我首先尝试的是:

devenv.exe /updateConfiguration

但这并没有解决问题。然后我运行:

devenv.exe /setup

它给出了以下错误信息:

The operation could not be completed. The requested operation requires elevation.

devenv.exe /SafeMode /log D:\temp

我在日志中看到的错误是:

Error loading UI library for package WebEditorPackage. HrLoadNativeUILibrary failed with 0x800a006f.
Error loading UI library for package Microsoft.VsSDK.ExtensibilityProjectFlavor.ExtensibilityProjectFlavorPackage. HrLoadNativeUILibrary failed with 0x800a006f.
Failed to find CTMENU resource '#1000' in loaded UI library.

我 运行 Visual Studio 作为管理员。问题仍然存在,但是当 运行之后以用户身份进入安全模式时,日志中不再有任何错误行。

我在正常启动时看到一个错误和许多警告:

ERROR Encountered an ArgumentException when trying to look up the key binding information for ({ef254ccf-cee3-43e9-a22c-3ae3ab08e7fe},256) in the scope {5efc7975-14bc-11cf-9b2b-00aa00573819}.
Unexpected system error mode before loading package [Microsoft.VisualStudio.Services.Promotions.PromotionsPackage]
Unexpected system error mode before loading package [InstallerPackage]
About to block on async service creation because the service was requested via GetService. This has the potential to deadlock. Async initializing services should be retrieved via GetServiceAsync.

PkgDef syntax or I/O error at line 1: Section header: additional characters after closing bracket
      [$RootKey$\Setup\[ProductName]]  80004005 - E_FAIL
PkgDef syntax or I/O error at line 3: Section header: additional characters after closing bracket
      "SrcPath"="[SourceDir]"  80004005 - E_FAIL
Could not process PkgDef file
      C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\Extensions\Community\Detection_Keys_Reg.pkgdef 

Visual Studio修复也没有解决问题。我正在使用 Visual Studio 15.6.5.


我 运行 sfc 检查 Windows 系统文件。

sfc /scannow

Beginning system scan.  This process will take some time.

Beginning verification phase of system scan.
Verification 100% complete.

Windows Resource Protection found corrupt files but was unable to fix some
of them. Details are included in the CBS.Log windir\Logs\CBS\CBS.log. For
example C:\Windows\Logs\CBS\CBS.log. Note that logging is currently not
supported in offline servicing scenarios.

有很多这样的错误:

CSI    000010f2 [DIRSD OWNER WARNING] Directory [l:48 ml:49]'\??\C:\Program Files\Windows Identity Foundation' is not owned but specifies SDDL in component c2wtsres, arch amd64, nonSxS, pkt {l:8 b:31bf3856ad364e35}
CSI    000010f3 [DIRSD OWNER WARNING] Directory [l:53 ml:54]'\??\C:\Program Files\Windows Identity Foundation\v3.5' is not owned but specifies SDDL in component c2wtsres, arch amd64, nonSxS, pkt {l:8 b:31bf3856ad364e35}
CSI    000010f4 Error - Overlap: Duplicate ownership for directory \??\C:\Program Files\Windows Identity Foundation in component c2wtsres, version 10.0.14393.0, arch amd64, nonSxS, pkt {l:8 b:31bf3856ad364e35}
CSI    000010f5 Error - Overlap: Duplicate ownership for directory \??\C:\Program Files\Windows Identity Foundation\v3.5 in component c2wtsres, version 10.0.14393.0, arch amd64, nonSxS, pkt {l:8 b:31bf3856ad364e35}

Process Monitor 日志显示 Git 和 VS 之间的切换。磁盘操作本身很快,但在 git.exe FileCloses C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32\bin\git.exe 之后,它几乎需要一秒钟才能关闭 C:\Windows。在 git.exe 的 QueryNameInformationFile 事件发生后将近一秒钟,它在 C:\Windows\System32\conhost.exe.

上执行 CloseFile

当没有什么特别的事情发生时,我进行了 Wireshark 捕获。我发现我的 PC 和公司代理 webdefence.cluster-x.websense.net 之间有很多流量。流量比我的同事多,而且他们没有看到错误。

使用有线、无线或在家中使用 VPN 连接时,问题仍然存在。

我怀疑是 NTFS 权限问题?


我试了 运行宁 SFCFix 没用。

SFCFix Has Crashed


Something has gone horribly wrong and SFCFix has crashed. Would you like SFCFix
to submit a crash report to the developer so that this problem can be fixed?
Type "y" for yes or "n" for no and press enter to continue:

我尝试的其他工具也没有成功。

D:\Tools>DISM /Online /Cleanup-Image /StartComponentCleanup /ResetBase

Deployment Image Servicing and Management tool
Version: 10.0.14393.0

Image Version: 10.0.14393.0

[===========                20.0%                          ]
The operation completed successfully.

D:\Tools>Dism /Online /Cleanup-Image /RestoreHealth

Deployment Image Servicing and Management tool
Version: 10.0.14393.0

Image Version: 10.0.14393.0

[==========================100.0%==========================]
Error: 0x800f081f

The source files could not be found.
Use the "Source" option to specify the location of the files that are required to restore the feature. For more information on specifying a source location, see http://go.microsoft.com/fwlink/?LinkId=243077.

The DISM log file can be found at C:\WINDOWS\Logs\DISM\dism.log

Tweaking.com - Windows Repair 2018 也无法修复文件权限。

Lenovo L460 - e-ID reader i7 SSD中可能是硬件问题。

系统已重新启动。 SFC 发现了一些错误并可以修复它们。 Wireshark 中的流量看起来正常,但问题仍然存在。有同事第一次登录系统出现同样的问题

我唯一注意到的另一件事是当 Opera 浏览器启动时,无法在第一分钟内显示新网页。网站一直加载很长时间。

删除此目录下的"Git"文件夹并重启VS

C:\Program Files (x86)\Microsoft Visual Studio17\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer

该文件夹会覆盖您正常的 Git 执行。

PS:如果您使用的不是 "Community" 版本,则相应地进行修改。 干杯