You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio 2019专业版公共扩展目录迁移修改方法咨询

Visual Studio 2019迁移后Unity扩展加载失败修复方案

问题背景

将Visual Studio 2019专业版从G:\迁移到L:\后,大部分功能正常,但部分扩展(如Visual Studio Tools for Unity)加载失败。重命名G盘Extensions目录后,ActivityLog.xml中出现以下错误:

<entry>
<record>675</record>
<time>2023/10/30 14:36:16.637</time>
<type>Error</type>
<source>VisualStudio</source>
<description>CreateInstance failed for package [UnityPackage]Source: 'mscorlib' Description: Could not load file or assembly 'file:///g:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\extensions\microsoft\visual studio tools for unity\SyntaxTree.VisualStudio.Unity.dll' or one of its dependencies. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'file:///g:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\extensions\microsoft\visual studio tools for unity\SyntaxTree.VisualStudio.Unity.dll' or one of its dependencies. The system cannot find the file specified.
File name: 'file:///g:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\extensions\microsoft\visual studio tools for unity\SyntaxTree.VisualStudio.Unity.dll'
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence securityEvidence)
   at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)
   at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
</description>
<guid>{B6546C9C-E5FE-4095-8D39-C080D9BD6A85}</guid>
<hr>80004005 - E_FAIL</hr>
<errorinfo></errorinfo>
</entry>

无需重装,可通过修改以下文本/配置文件解决:

修复步骤

1. 更新Unity扩展的注册配置文件

在L盘VS安装目录的Common7\IDE\Extensions\Microsoft\Visual Studio Tools for Unity路径下:

  • 找到所有.pkgdef文件(如SyntaxTree.VisualStudio.Unity.pkgdef),用文本编辑器打开,将所有G:\Program Files (x86)\Microsoft Visual Studio\2019\Professional替换为L:\Program Files (x86)\Microsoft Visual Studio\2019\Professional,保存后关闭。
  • 检查extension.vsixmanifest文件,确认其中的安装路径指向L盘,若有硬编码旧路径则替换。

2. 编辑VS私有注册表

VS有独立的私有注册表,需加载后修改:

  1. 以管理员身份打开命令提示符,执行命令加载私有注册表:
    reg load HKLM\VS2019Private "L:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\PrivateRegistry.bin"
    
  2. 打开注册表编辑器(regedit),导航到HKLM\VS2019Private,使用搜索功能查找所有包含旧G盘路径的条目,逐一替换为L盘对应路径。
  3. 修改完成后,执行命令卸载私有注册表:
    reg unload HKLM\VS2019Private
    

3. 清理VS缓存文件

删除以下路径的缓存,避免VS读取旧路径信息:

  • 删除%LOCALAPPDATA%\Microsoft\VisualStudio\16.0_*\ComponentModelCache目录下的所有文件(16.0_*为VS 2019的版本标识目录)
  • 删除%LOCALAPPDATA%\Microsoft\VisualStudio\16.0_*\Extensions目录下的缓存文件(若有记录旧路径的配置,可直接删除整个目录,VS重启后会重新生成)

4. 验证Unity编辑器的外部工具配置

打开Unity编辑器,依次进入编辑 → 首选项 → 外部工具,确保“外部脚本编辑器”选择的是L盘的Visual Studio 2019,而非指向旧G盘的快捷方式。


内容的提问来源于stack exchange,提问作者Robert Koernke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 03:45:14