diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2020-02-23 08:18:12 +0100 |
|---|---|---|
| committer | j-p <jp_bruyere@hotmail.com> | 2020-05-10 00:50:02 +0200 |
| commit | 5612fec80cf3035f1726fefe3c54a32acc577e84 (patch) | |
| tree | 85725d9594de03d89e62be177d31534982086026 /Samples | |
| parent | 81a8401cfd8942ae06afc876ddd46e632922fd53 (diff) | |
wip
Diffstat (limited to 'Samples')
| -rw-r--r-- | Samples/HelloWorld/HelloWorld.csproj | 8 | ||||
| -rw-r--r-- | Samples/HelloWorld/main.cs | 74 |
2 files changed, 72 insertions, 10 deletions
diff --git a/Samples/HelloWorld/HelloWorld.csproj b/Samples/HelloWorld/HelloWorld.csproj index 7d3574d0..5a976be0 100644 --- a/Samples/HelloWorld/HelloWorld.csproj +++ b/Samples/HelloWorld/HelloWorld.csproj @@ -1,6 +1,6 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> - <TargetFramework>net472</TargetFramework> + <TargetFramework>netcoreapp3.1</TargetFramework> <OutputType>Exe</OutputType> <EnableDefaultNoneItems>false</EnableDefaultNoneItems> <ReleaseVersion>0.8.0</ReleaseVersion> @@ -24,17 +24,17 @@ </EmbeddedResource> </ItemGroup> <ItemGroup> - <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.4.0" /> <!-- <PackageReference Include="Microsoft.CodeAnalysis.Features" Version="3.4.0" />--> <PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="3.4.0" /> + <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.4.0" /> <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.4.0" /> <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="3.4.0" /> </ItemGroup> - <ItemGroup> + <!--<ItemGroup> <PackageReference Include="SQLitePCLRaw.core" Version="2.0.2" /> <PackageReference Include="System.Memory" Version="4.5.3" /> - </ItemGroup> + </ItemGroup> --> <ItemGroup> <PackageReference Include="Microsoft.Build" Version="16.4.0"> 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 () //{ |