public void GetAssemblySymbolsAndSyntaxTreesFromAProject()
{
var source = @"
class Program
{
static void Main()
{
}
}";
var solutionId = SolutionId.CreateNewId();
ProjectId projectId;
DocumentId documentId;
var solution = Solution.Create(solutionId)
.AddCSharpProject("MyProject", "MyProject", out projectId)
.AddMetadataReference(projectId, MetadataReference.CreateAssemblyReference("mscorlib"))
.AddDocument(projectId, "MyFile.cs", source, out documentId);
// If you wish to try against a real project you could use code like
// var project = Solution.LoadStandAloneProject("<Path>");
// OR var project = Workspace.LoadStandAloneProject("<Path>").CurrentSolution.Projects.First();
var project = solution.Projects.Single();
var compilation = project.GetCompilation();
// Get AssemblySymbols for above compilation and the assembly (mscorlib) referenced by it.
IAssemblySymbol compilationAssembly = compilation.Assembly;
IAssemblySymbol referencedAssembly = compilation.GetReferencedAssemblySymbol(project.MetadataReferences.Single());
Assert.IsTrue(compilation.GetTypeByMetadataName("Program").ContainingAssembly.Equals(compilationAssembly));
Assert.IsTrue(compilation.GetTypeByMetadataName("System.Object").ContainingAssembly.Equals(referencedAssembly));
CommonSyntaxTree tree = project.Documents.Single().GetSyntaxTree();
Assert.AreEqual("MyFile.cs", tree.FilePath);
}