调试 Visual Studio 2017 扩展未找到程序集

Debugging Visual Studio 2017 Extension Does Not Find Assembly

我正在尝试更新我的 Diff All Files Visual Studio extension 以支持 VS 2017。调试我的扩展时它抱怨找不到所需的程序集:

System.Windows.Markup.XamlParseException occurred
  HResult=0x80131501
  Message=Could not load file or assembly 'QuickConverter, PublicKeyToken=9c892aa7bc2af2cf' or one of its dependencies. The system cannot find the file specified.
  Source=PresentationFramework
  StackTrace:
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at VS_DiffAllFiles.Sections.DiffAllFilesSectionControl.InitializeComponent() in D:\dev\Git\VS.DiffAllFiles\VS.DiffAllFiles.VS2017\obj\Debug\DiffAllFilesSectionControl.xaml:line 1
   at VS_DiffAllFiles.Sections.DiffAllFilesSectionControl..ctor(DiffAllFilesSectionBase parentSection) in D:\dev\Git\VS.DiffAllFiles\VS.DiffAllFiles\Sections\DiffAllFilesSectionControl.xaml.cs:line 18
   at VS_DiffAllFiles.DiffAllFilesBaseClasses.DiffAllFilesSectionBase..ctor() in D:\dev\Git\VS.DiffAllFiles\VS.DiffAllFiles\DiffAllFilesBaseClasses\DiffAllFilesSectionBase.cs:line 82
   at VS_DiffAllFiles.DiffAllFilesBaseClasses.TfsDiffAllFilesSectionBase..ctor()
   at VS_DiffAllFiles.DiffAllFilesBaseClasses.SupportsIncludedAndExcludedChangesTfsSectionBase..ctor()
   at VS_DiffAllFiles.Sections.PendingChangesSection..ctor() in D:\dev\Git\VS.DiffAllFiles\VS.DiffAllFiles\Sections\PendingChangesSection.cs:line 27

Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'QuickConverter, PublicKeyToken=9c892aa7bc2af2cf' or one of its dependencies. The system cannot find the file specified.

我已确认该文件存在于 C:\Users\Dan.Schroeder\AppData\Local\Microsoft\VisualStudio.0_b920d444Exp\Extensions\DansKingdom\Diff All Files for VS2017.0\QuickConverter.dll 并且具有正确的名称和公钥。

我也有captured the Fusion Logs(即Assembly Binding Log Viewer)来捕获绑定错误,看来VS并没有在它所在的目录中寻找dll文件;它不是在实验性扩展目录中查找,而是在实际的 VS 2017 目录中查找。我捕获了这个错误,还有一个包含版本的完全限定名称的错误,这是程序集的正确版本:

*** Assembly Binder Log Entry  (4/13/2017 @ 1:18:51 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\Common7\IDE\devenv.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = QuickConverter, PublicKeyToken=9c892aa7bc2af2cf
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: QuickConverter, PublicKeyToken=9c892aa7bc2af2cf | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = devenv.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\Dan.Schroeder\AppData\Local\Microsoft\VisualStudio.0_b920d444Exp\devenv.exe.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PublicAssemblies/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PublicAssemblies/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/Debugger/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/Debugger/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/x86/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/x86/QuickConverter/QuickConverter.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PublicAssemblies/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PublicAssemblies/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/Debugger/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/Debugger/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/QuickConverter/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/x86/QuickConverter.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/Common7/IDE/PrivateAssemblies/DataCollectors/x86/QuickConverter/QuickConverter.EXE.
LOG: All probing URLs attempted and failed.

关于为什么 VS 没有在正确的位置查找以加载该程序集的任何想法?还是我还缺少其他东西?

我在为 VS 2012、2013 或 2015 开发扩展时没有 运行 解决这个问题。我 debugging the Visual Studio Extension 通过提供 rootsuffix Exp 命令行参数,只是就像我对以前的 Visual Studio 版本所做的那样。

如果需要,您可以 download the source code 并自己重现问题(这是 AddVs2017Support 分支);只需卸载除 VS.DiffAllFiles 和 VS.DiffAllFiles.VS2017 项目之外的所有项目。

感谢任何 thoughts/suggestions。谢谢。


更新 1

根据 the link that Hans Passant provided,我尝试将 .pkgdef 文件添加到我的项目并将其作为资产包含在我的 .vsixmanifest 文件中,但问题仍然存在。当我查看 C:\Users\Dan.Schroeder\AppData\Local\Microsoft\VisualStudio.0_b920d444Exp\devenv.exe.config 文件时,我仍然没有看到对我的程序集的任何引用,因此它似乎没有向该文件添加任何应有的内容。此外,融合日志仍然报告与我上面提供的完全相同的信息。

当我尝试 generate the .pkgdef file manually(因为它应该作为构建过程的一部分自动完成)时,出现以下错误。我不确定在 Visual Studio 之外生成它时是否可以预期(我只是使用常规命令提示符)。

C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\VSSDK\VisualStudioIntegration\Tools\Bin>CreatePkgDef.exe /out="C:\Temp\Def.pkgdef" "C:\Users\Dan.Schroeder\AppData\Local\Microsoft\VisualStudio.0_b920d444Exp\Extensions\DansKingdom\Diff All Files for VS2017.0\VS.DiffAllFiles.VS2017.dll"
Visual Studio (R) PkgDef Creation Utility.
Copyright (c) Microsoft Corporation. All rights reserved.

Assembly: VS.DiffAllFiles.VS2017 1.0.0.0
Output file: C:\Temp\Def.pkgdef

CreatePkgDef : error : ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at Microsoft.VisualStudio.Tools.CreatePkgDef.ProcessAssembly(String fileName, Hive hive, PkgDefContext context, Boolean register, RegistrationMode mode) in F:\dd\src\vssdk\VSIntegration\Tools\src\CreatePkgDef\CreatePkgDef.cs:line 261
   at Microsoft.VisualStudio.Tools.CreatePkgDef.DoCreatePkgDef(InputArguments inputArguments) in F:\dd\src\vssdk\VSIntegration\Tools\src\CreatePkgDef\CreatePkgDef.cs:line 164
   at Microsoft.VisualStudio.Tools.CreatePkgDef.Main(String[] arguments) in F:\dd\src\vssdk\VSIntegration\Tools\src\CreatePkgDef\CreatePkgDef.cs:line 85
Could not load file or assembly 'Microsoft.VisualStudio.Shell.15.0, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.VisualStudio.Shell.15.0, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.VisualStudio.Shell.15.0, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

同样,这些最新更改已推送到 AddVs2017Support 分支下的 the source code on GitHub,任何关心查看代码以尝试发现问题的人都可以使用。


更新 2

我也尝试重置 Visual Studio 2017 实验实例,以及在我的常规(非实验)VS 2017 实例上安装 vsix,但它仍然会导致相同的错误,即无法找到程序集。

如果我手动将 dll 文件复制到 C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\Common7\IDE 目录,那么它会被找到并且我不再收到错误。我只是不确定为什么 Visual Studio 没有在我的扩展目录中寻找它,而那里确实存在完全相同的文件。

我 运行 遇到了类似的情况,并且得到了相同的错误和融合日志结果。为了找到问题的根源,我最终做的是在调试时启用 activity 登录实验实例。因此,在 VSIX 项目的调试设置中,将启动参数更改为“/rootsuffix Exp /log”。

调试扩展并重现问题。

然后检查位于以下位置的 activity 日志文件:C:\Users\%username%\AppData\Roaming\Microsoft\VisualStudio.0_796eceb7Exp\ActivityLog.xml

在我的特定实例中,我使用的是带有向导扩展的项目模板。在项目的 .vstemplate 文件中,有一个神奇的字符串,其中包含向导实现的名称空间和 classname。我重命名了 class 但没有更新模板中的字符串。

我一直无法确定此问题的根本原因。我最初所做的是在 Visual Studio 中创建一个新的 VS2017 VSIX 项目,然后将我的 VS2015 VSIX 项目中的所有文件包含在其中,这就是我遇到此错误的时候。

最终对我有用的是删除那个 VS2017 项目,而只是复制粘贴我现有的 VS2015 项目,然后将 .csproj 和其他文件重命名为 2017 而不是 2015。然后我打开它VS 2017 中的项目并让它进行升级迁移,然后更新 vsixmanifest 文件以支持 VS 2017。完成后,一切都按预期进行。

您可以尝试在您的 VSIX 项目的 AssemblyInfo.cs 中添加以下代码:

[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\QuickConverter.dll")]

我尝试使用 VS 2017 update 7 并运行良好。

经过几天的研究,我能够使用 VS 2017 让它为我工作。 普遍的问题确实是 Visual Studio 在错误的地方寻找程序集。正如我之前所怀疑的那样,签名没有问题。 我的 VSIX/Wizard 程序集包含在 VSIX 中,但我安装它后,VS 找不到它。如果您查看 C:\Users\Username\AppData\Local\Microsoft\VisualStudio.0_ff857330Exp\Extensions 文件夹,程序集就在那里。 似乎 VS 并没有在那里搜索它。

因此解决方案是设置 "Install root" 属性。

  • 在 Visual Studio select 你的 VSIX 项目中并转到 属性 window.
  • 在选项卡 "VSIX" 下,将 "Install root" 从 "Default" 更改为例如"PublicAssemblies"(您也可以选择其他选项,但 PublicAssemblies 工作正常)
  • 然后您必须编辑 source.extension.vsixmanifest 并设置 "This VSIX is installed for all users"。否则您将无法使用更改后的安装目录进行构建。

然后,清单中引用的程序集将在 VSIX 安装时复制到位置 C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\PublicAssemblies,在使用已安装的模板时很容易找到它们。据我所知,无法以其他方式更改默认安装路径或在没有提升权限的情况下进行更改。

希望这个答案可以节省您几天的研究和尝试时间。