我是Visual Studio扩展程序的新手,并尝试了一些来自GitHub的示例以及一些有用的建议,并取得了一些成功。我试图创建一个ToolWindow来处理当前打开的解决方案的结构,这在技术上对Microsoft.VisualStudio.LanguageServices
命名空间没有问题。只要我不使用该命名空间中的任何内容,ToolWindow本身就可以工作 - 特别是下面的被调用函数在我的窗口的构造函数中初始化解决方案信息:
private void ReloadSolutionInformation()
{
var componentModel = (IComponentModel)SmartOptionsEditorPackage.GetGlobalService(typeof(SComponentModel));
VisualStudioWorkspace workspace = componentModel.GetService<VisualStudioWorkspace>();
Solution solution = workspace.CurrentSolution;
this.Solutions.Clear(); // some collection of SolutionNode instances
// create and add custom tree node with solution information
var solutionNode = new SolutionNode(solution.FilePath);
this.Solutions.Add(solutionNode);
// recurse through projects etc.
PopulateSolutionWithProjects(solutionNode, solution);
}
当我在Visual Studio 2017的实验实例中运行扩展以调试它时,我在构造函数中获得以下异常(原始是德语,我的翻译可能不是100%准确),其中调用上述方法:
文件或程序集&#34; Microsoft.VisualStudio.LanguageServices,Version = 2.3.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35&#34;或者找不到其中一个依赖项。系统找不到该文件。
StackTrace:在MyAssembly.MyToolWindow.ReloadSolutionInformation() 在MyAssembly.MyToolWindow..ctor() 在MyAssembly.MyToolWindowPane..ctor()
FileName:Microsoft.VisualStudio.LanguageServices,Version = 2.3.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35
此外,我在构建后注意到以下警告:
CS1762:为嵌入式互操作程序集创建了一个引用&quot; Microsoft.VisualStudio.Shell.Interop.10.0,Version = 10.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a&#39;因为对程序集创建的程序集的间接引用是Microsoft.VisualStudio.LanguageServices,Version = 2.3.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35&#39;。考虑更改“嵌入互操作类型”&#39;任何一个集会的财产。
将构建输出详细程度设置为诊断,我只发现上述警告而没有进一步的信息。检查构建输出目录,我看到包含所有引用的DLL,但VSIX中缺少所有Microsoft.VisualStudio.*
DLL,Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime.dll
除外。据我了解互操作程序集,我认为它们是由VisualStudio提供的,所以我不必嵌入它们,是吗?
每个引用的引用属性Embed Interop Types
都设置为false。我试图根据我发现的一些建议改变它,但那并没有奏效。我定位.Net 4.6.2。
在经历了太多令人沮丧的试验 - 尤其是错误的晚上之后,我仍然不知道如何解决这个问题。这包括重新安装NuGet包,重新启动所有内容,重置实验实例以及逐步删除和重新添加引用作为本地DLL和NuGetPackage。在之前的编辑中,我发布了缩短的项目文件内容,由于输入字符限制,我现在必须将其删除。相反,这是fusionlog的输出:
=== Zustandsinformationen vor Bindung ===
LOG: DisplayName = Microsoft.VisualStudio.LanguageServices, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/
LOG: Ursprünglicher PrivatePath = NULL
Aufruf von Assembly : MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: Diese Bindung startet im LoadFrom-Load-Kontext.
WRN: Das systemeigene Image wird nicht im LoadFrom-Kontext durchsucht. Das systemeigene Image wird nur im Standard-Load-Kontext durchsucht, z. B. Assembly.Load().
LOG: Die Anwendungskonfigurationsdatei wird verwendet: C:\Users\me\AppData\Local\Microsoft\VisualStudio\15.0_15d7a44dExp\devenv.exe.config
LOG: Die Hostkonfigurationsdatei wird verwendet:
LOG: Die Computerkonfigurationsdatei von C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config wird verwendet.
LOG: Verweis nach der Richtlinie: Microsoft.VisualStudio.LanguageServices, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PublicAssemblies/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PublicAssemblies/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Platform/Debugger/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Platform/Debugger/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PrivateAssemblies/DataCollectors/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PrivateAssemblies/DataCollectors/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PrivateAssemblies/DataCollectors/x86/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PrivateAssemblies/DataCollectors/x86/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PublicAssemblies/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PublicAssemblies/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/TemplateProviders/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Platform/Debugger/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Platform/Debugger/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Platform/DiagnosticsHub/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PrivateAssemblies/DataCollectors/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PrivateAssemblies/DataCollectors/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PrivateAssemblies/DataCollectors/x86/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/PrivateAssemblies/DataCollectors/x86/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/USERS/ME/APPDATA/LOCAL/MICROSOFT/VISUALSTUDIO/15.0_15D7A44DEXP/EXTENSIONS/AUTHOR/MY ASSEMBLY/1.0/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/USERS/ME/APPDATA/LOCAL/MICROSOFT/VISUALSTUDIO/15.0_15D7A44DEXP/EXTENSIONS/AUTHOR/MY ASSEMBLY/1.0/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.DLL.
LOG: Download von neuem URL file:///C:/USERS/ME/APPDATA/LOCAL/MICROSOFT/VISUALSTUDIO/15.0_15D7A44DEXP/EXTENSIONS/AUTHOR/MY ASSEMBLY/1.0/Microsoft.VisualStudio.LanguageServices.EXE.
LOG: Download von neuem URL file:///C:/USERS/ME/APPDATA/LOCAL/MICROSOFT/VISUALSTUDIO/15.0_15D7A44DEXP/EXTENSIONS/AUTHOR/MY ASSEMBLY/1.0/Microsoft.VisualStudio.LanguageServices/Microsoft.VisualStudio.LanguageServices.EXE.
您在this ZIP file中找到了一个最小解决方案示例。在这里,我使用新的VSIX项目创建了一个新的解决方案,通过向导添加了一个ToolWindow,添加了我的重要代码,解决了缺少的引用,开始调试并收到了相同的旧FileNotFoundException
。
有人在这看到问题吗?提前谢谢。
答案 0 :(得分:1)
您必须使用Visual Studio使用或更低版本的库版本。
对于2017社区,可以在
中找到C:\ Program Files(x86)\ Microsoft Visual 工作室\ 2017 \社区\ Common7 \ IDE \ CommonExtensions \微软\ ManagedLanguages \ VBCSharp \ LanguageServices
现在在Visual Studio 2017版本15.2中 Microsoft.CodeAnalysis.Workspaces.dll,Microsoft.VisualStudio.LanguageServices.dll,Microsoft.CodeAnalysis.EditorFeatures.Text的版本为2.2.0。
所以在NuGet中安装或更新它们到2.2.0版本,不需要将它们包含在vsix
中您可以通过将<ForceIncludeInVSIX>true</ForceIncludeInVSIX>
添加到.csproj文件包含在VSIX中的较新版本的Microsoft.VisualStudio.LanguageServices:
<Reference Include="Microsoft.VisualStudio.LanguageServices, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <HintPath>..\packages\Microsoft.VisualStudio.LanguageServices.2.3.1\lib\net46\Microsoft.VisualStudio.LanguageServices.dll</HintPath> <ForceIncludeInVSIX>true</ForceIncludeInVSIX> </Reference>
但接下来我们会得到其他错误。
System.InvalidCastException:'无法将类型为'Microsoft.VisualStudio.LanguageServices.RoslynVisualStudioWorkspace'的对象强制转换为'Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace
Visual Studio 2017版本15.3使用2.3.2版本。您的扩展程序使用较低版本2.2.0并将在那里工作。如果将NuGet中的组件更新为2.3.2,则扩展将在15.3中起作用,而在15.2中不起作用
现在使用2.2.0版本。
答案 1 :(得分:0)