我试图在特定符号的解决方案中查找所有引用,但 Locations 属性始终为空。我加载独立项目,找到我正在寻找的符号,然后要求编译给我一个符号的所有引用。我得到一个引用(正确,因为只有一个属性使用),但 Locations 属性为空。这是代码
IWorkspace workspace = Workspace.LoadStandAloneProject(projectPath);
var solution = workspace.CurrentSolution;
var searchAttributeName = typeof(OneToOneAttribute).FullName;
var project = solution.Projects.First();
var compilation = project.GetCompilation();
var attSymbol = (NamedTypeSymbol)compilation.GetTypeByMetadataName(searchAttributeName);
var references = attSymbol.FindReferences(solution);
foreach (ReferencedSymbol referencedSymbol in references)
{
foreach (ReferenceLocation location in referencedSymbol.Locations)
{
}
}