public IEnumerable <CSDocument> GetProjectDocuments(ProjectID project) { var docs = Workspace.CurrentSolution.GetProject(project).Documents; var list = new List <CSDocument>(); foreach (var doc in docs) { list.Add(new CSDocument(doc)); } return(list); }
public DocumentID(ProjectID pid, Guid guid = default, string debugName = null) : base(guid, debugName) { ProjectID = pid; }
/// <summary> /// Adds a document to the workspace. /// </summary> public DocumentID AddDocument(ProjectID projectId, string name, string text) { return(Workspace.AddDocument(projectId, name, SourceText.From(text)).Id); }
public (Assembly DLL, IEnumerable <CSDiagnostic> ErrorMessages) CompileProjectToDLL(ProjectID id, IEnumerable <string> assemblyFilenames = null) { if (assemblyFilenames == null) { assemblyFilenames = References; } //(Assembly DLL, IEnumerable<Diagnostic> ErrorMessages) Assembly dll = null; IEnumerable <Diagnostic> compileErrors = null; var references = new List <PortableExecutableReference>() { MetadataReference.CreateFromFile(typeof(object).Assembly.Location) }; foreach (string name in assemblyFilenames) { references.Add(MetadataReference.CreateFromFile(name)); } var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); Project project = Workspace.CurrentSolution.GetProject(id); project = project.WithCompilationOptions(options).WithMetadataReferences(references); using (var stream = new MemoryStream()) { EmitResult result = project.GetCompilationAsync().Result.Emit(stream); if (!result.Success) { compileErrors = result.Diagnostics; } else { string filename = $"{GetAssemblyName(id)}.dll"; using (FileStream file = File.Create(filename)) { stream.Seek(0, SeekOrigin.Begin); stream.CopyTo(file); } dll = Assembly.LoadFrom(Path.GetFullPath(filename)); } } return(dll, compileErrors?.Select(x => new CSDiagnostic(x))); }
public string GetAssemblyName(ProjectID id) { return(Workspace.CurrentSolution.GetProject(id).AssemblyName); }