aboutsummaryrefslogtreecommitdiffstatsci
path: root/Samples/HelloWorld/main.cs
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2020-02-23 08:18:12 +0100
committerj-p <jp_bruyere@hotmail.com>2020-05-10 00:50:02 +0200
commit5612fec80cf3035f1726fefe3c54a32acc577e84 (patch)
tree85725d9594de03d89e62be177d31534982086026 /Samples/HelloWorld/main.cs
parent81a8401cfd8942ae06afc876ddd46e632922fd53 (diff)
wip
Diffstat (limited to 'Samples/HelloWorld/main.cs')
-rw-r--r--Samples/HelloWorld/main.cs74
1 files changed, 68 insertions, 6 deletions
diff --git a/Samples/HelloWorld/main.cs b/Samples/HelloWorld/main.cs
index 75a2683b..c95ee8e4 100644
--- a/Samples/HelloWorld/main.cs
+++ b/Samples/HelloWorld/main.cs
@@ -1,19 +1,15 @@
using System;
-using System.CodeDom.Compiler;
using System.Collections.Generic;
-using System.Composition;
+using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Reflection;
-using System.Reflection.Emit;
using System.Threading.Tasks;
using Crow;
-using Crow.IML;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Completion;
-using Microsoft.CodeAnalysis.CSharp;
-using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Emit;
+using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.MSBuild;
using Microsoft.CodeAnalysis.Text;
@@ -329,11 +325,71 @@ namespace HelloWorld
var host = MefHostServices.Create (MSBuildMefHostServices.DefaultAssemblies);
+ Solution sol = null;
+
+ //using (var ws = new AdhocWorkspace ()) {
+ // ws.WorkspaceFailed += (sender, e) => Console.WriteLine ($"Workspace error: {e.Diagnostic}");
+ // ws.WorkspaceChanged += (sender, e) => Console.WriteLine ($"Workspace changed: {e.Kind} proj={e.ProjectId} doc={e.DocumentId}");
+
+ // var solId = SolutionId.CreateNewId ();
+ // SolutionInfo solutionInfo = SolutionInfo.Create (solId, VersionStamp.Create (), @"/tmp/testSol/testSolu.sln");
+
+ // sol = ws.AddSolution (solutionInfo);
+ // if (!ws.TryApplyChanges (sol))
+ // Console.WriteLine ("error saving sol");
+
+ // Microsoft.CodeAnalysis.Host.IPersistentStorageService p = ws.Services.PersistentStorage;
+
+ // using (Stream s = new FileStream (solutionInfo.FilePath, FileMode.Create)) {
+ // IPersistentStorage store = p.GetStorage (sol);
+
+ // if (!await p.GetStorage (sol).WriteStreamAsync ("testSol", s))
+ // Console.WriteLine ("error saving sol");
+ // }
+
+
+
+ //var projectInfo = ProjectInfo.Create (ProjectId.CreateNewId (),
+ // VersionStamp.Create (),
+ // "testSolu",
+ // "testSolu.dll",
+ // LanguageNames.CSharp,
+ // @"/tmp/testSol/testSolu.csproj");
+
+
+ // var proj = ws.AddProject (projectInfo);
+ // var sourceText = SourceText.From ("public class A { }");
+ // ws.AddDocument (DocumentInfo.Create (DocumentId.CreateNewId (proj.Id), "ClassA.cs"));
+
+
+
+ // if (!ws.CanApplyChange (ApplyChangesKind.AddDocument))
+ // Console.WriteLine ("cant apply add Document");
+ //}
+
using (var workspace = MSBuildWorkspace.Create (globalProperties)) {
//workspace. Properties["BuildingInsideVisualStudio"] = "false";
workspace.WorkspaceFailed += (sender, e) => Console.WriteLine ($"Workspace error: {e.Diagnostic}");
+ workspace.WorkspaceChanged += (sender, e) => Console.WriteLine ($"Workspace changed: {e.Kind} proj={e.ProjectId} doc={e.DocumentId}");
+
+ IPersistentStorageService p = workspace.Services.PersistentStorage;
+ Console.WriteLine (p);
+
+
+
+ //workspace.Services.PersistentStorage.GetStorage(sol).WriteStreamAsync()
+
+
Console.WriteLine ($"Opening Solution {slnPath}");
var solution = await workspace.OpenSolutionAsync (slnPath, new ProgressLog ());
+
+ IPersistentStorage ip = p.GetStorage (solution);
+ Console.WriteLine (ip);
+ using (Stream s = new FileStream (@"/tmp/testSol/testSolu.sln", FileMode.Create)) {
+ if (!await ip.WriteStreamAsync ("testSolu", s))
+ Console.WriteLine ("error saving sol");
+ }
+
Console.WriteLine ($"Proj Count:{solution.Projects.Count ()}");
foreach (Project project in solution.Projects) {
Console.WriteLine ($"Compiling project:{project.FilePath}");
@@ -341,6 +397,9 @@ namespace HelloWorld
Compilation compilation = await project.GetCompilationAsync ();
Document doc = project.Documents.First ();
+ Task<SourceText> src = doc.GetTextAsync ();
+
+
CompletionService.GetService (doc);
using (var ms = new MemoryStream ()) {
EmitResult result = compilation.Emit (ms);
@@ -362,9 +421,11 @@ namespace HelloWorld
//workspace.TryApplyChanges()
}
+
Console.WriteLine ($"end.");
}
}
+
class ProgressLog : IProgress<ProjectLoadProgress>
{
public void Report (ProjectLoadProgress value)
@@ -373,6 +434,7 @@ namespace HelloWorld
}
}
+
}
//void compile ()
//{