none
How can I get an IAssemblySymbol for a IProject?

    질문

  • I've loaded a project via Workspace.LoadStandAloneProject and now I'd like to get ahold of the AssemblySymbol that represents the project. Is there a simple way to do this? Right now I have to use the ISemanticModel to resolve a syntax element in a SyntaxTree I get from an IDocument that I got from an IProject and then walk upto the AssemblySymbol. 

    Shouldn't IProject contain an ICompilation that can enumerate all the referenced AssemblySymbols -- both metadata and project reference -- and enumerate all the trees for each document?

    Thanks,
    Chris

    2012년 2월 14일 화요일 오후 11:18

답변

  • You should be able to get to the AssemblySymbols, SyntaxTrees etc. as follows. (Of course you can also get to the MetadataReferences \ SyntaxTrees via the Compilation instead of using the IProject.)

    var compilation = project.GetCompilation();
    var currentAssembly = project.GetCompilation().Assembly;
    var referenceAssembly = compilation.GetReferencedAssemblySymbol(project.MetadataReferences.First());
    var tree = project.Documents.First().GetSyntaxTree();

    Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team

    • 답변으로 표시됨 kingces95 2012년 2월 15일 수요일 오전 12:50
    2012년 2월 15일 수요일 오전 12:06
    소유자

모든 응답

  • You should be able to get to the AssemblySymbols, SyntaxTrees etc. as follows. (Of course you can also get to the MetadataReferences \ SyntaxTrees via the Compilation instead of using the IProject.)

    var compilation = project.GetCompilation();
    var currentAssembly = project.GetCompilation().Assembly;
    var referenceAssembly = compilation.GetReferencedAssemblySymbol(project.MetadataReferences.First());
    var tree = project.Documents.First().GetSyntaxTree();

    Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team

    • 답변으로 표시됨 kingces95 2012년 2월 15일 수요일 오전 12:50
    2012년 2월 15일 수요일 오전 12:06
    소유자
  • Oh, duh. I keep not guessing if I have to use a "Get" prefix...
    • 편집됨 kingces95 2012년 2월 15일 수요일 오전 1:04
    2012년 2월 15일 수요일 오전 12:50