问题描述
我正在学习 Roslyn 并第一次尝试它.我编写了一个小代码片段来加载解决方案并获取对工作区的引用.
I'm learning Roslyn and trying it out for the first time. I've written a small code snippet to load a solution and get a reference to a workspace.
IWorkspace workspace = Workspace.LoadSolution(solutionPath);
foreach (IProject project in workspace.CurrentSolution.Projects)
{
CommonCompilation objCompilation = project.GetCompilation();
}
return workspace;
但是我在第一行遇到了一个异常.异常详情如下.
But I'm getting an exception in the first line. The exception details are given below.
消息:预期的全球线路.
堆栈跟踪:
在Roslyn.Services.Host.SolutionFile.ParseGlobal(文本阅读器阅读器)
在 Roslyn.Services.Host.SolutionFile.Parse(TextReader reader)
在Roslyn.Services.Host.LoadedWorkspace.LoadSolution(SolutionId)solutionId, String filePath)
在Roslyn.Services.Host.LoadedWorkspace.OpenSolution(String fileName)
在 Roslyn.Services.Host.LoadedWorkspace.LoadSolution(String解决方案文件名、字符串配置、字符串平台、布尔值enableFileTracking)
在Roslyn.Services.Workspace.LoadSolution(String solutionFileName, String配置,字符串平台,布尔值 enableFileTracking)
在ros2.Program.GetWorkspace(String solutionPath) 中c:\users\amnatu\documents\visual studio2015\Projects\Ros2\Ros2\Program.cs:line 30
stack trace :
at Roslyn.Services.Host.SolutionFile.ParseGlobal(TextReader reader)
at Roslyn.Services.Host.SolutionFile.Parse(TextReader reader)
at Roslyn.Services.Host.LoadedWorkspace.LoadSolution(SolutionId solutionId, String filePath)
at Roslyn.Services.Host.LoadedWorkspace.OpenSolution(String fileName)
at Roslyn.Services.Host.LoadedWorkspace.LoadSolution(String solutionFileName, String configuration, String platform, Boolean enableFileTracking)
at Roslyn.Services.Workspace.LoadSolution(String solutionFileName, String configuration, String platform, Boolean enableFileTracking)
at Ros2.Program.GetWorkspace(String solutionPath) in c:\users\amnatu\documents\visual studio 2015\Projects\Ros2\Ros2\Program.cs:line 30
我 引用此链接 显示了我面临的相同问题.但是,删除 EndProject
和 Global
之间的空格的解决方案在我的情况下并不真正适用,因为我的解决方案文件之间没有任何空格.
I referred to this link which shows the same issue that I faced. However, the solution of removing the space between EndProject
and Global
isn't really applicable in my case as my solution file doesn't have any space between them.
我在这里遗漏了什么吗?
有关如何解决此问题的任何建议?
Am I missing anything here?
Any suggestions on how to resolve this issue?
推荐答案
对于延迟响应深表歉意.@JoshVarty 的评论帮助我理解了这个问题.
Apologies for the delayed response. The comment by @JoshVarty helped me understand the issue.
我确实在使用过时的版本,不得不使用最新的 Microsoft.CodeAnalysis
库.在我进行了这些更改并相应地更新了所有类之后,一切都运行良好.
I was indeed using the out dated version and had to use the latest Microsoft.CodeAnalysis
library. After I made these changes and updated all classes accordingly, everything worked perfectly.
谢谢 JoshVarty.
Thanks JoshVarty.!
这篇关于“预期的全球线."使用 Roslyn 加载解决方案时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!