Introduction to Roslyn
of 58
/58
-
Author
yuki-igarashi -
Category
Engineering
-
view
434 -
download
2
Embed Size (px)
description
プログラミング生放送勉強会 第28回@東北大学で発表した資料です。 間違い等も多くあるかと思いますので、その際はご指摘いただければと思います。
Transcript of Introduction to Roslyn
- Introduction to Roslyn 2014531 28 @bonprosoft 1
- 2
- Twitter: @bonprosoft () 0x13 Microsoft Student Partners Fellow 3
- Microsoft Student Partners Microsoft http://www.microsoft.com/ja-jp/education/msp.aspx 4
- Roslyn 5
- IS THE COMPILER A BLACK BOX? () 6
- IS THE COMPILER A BLACK BOX? 7
- IS THE COMPILER A BLACK BOX? 8 Syntax Highlighting And more IntelliSense()
- IS THE COMPILER A BLACK BOX? IDE 2 9
- 1 1 API Roslyn 10
- 11 Class Field public Foo private string X CompilerCompilerSource code Source code Source File Source code Source code .NET Assembly Meta-programming Read-Eval-Print Loop Language Object Model DSL Embedding BUILD 2011 TOOL-816T: Future directions for C# and Visual Basic
- Roslyn http://vsshare.azurewebsites.net/ 12
- Roslyn Visual Studio RoslynSignalR 13
- Roslyn 14 Server Presenter PC (Visual Studio) SignalR Visual Studio Roslyn& SignalR
- Roslynclone 15
- Roslynclone 16 FizzBuzz
- Roslyn 17
- .NET IL 18 .method public static void Main() cil managed { .entrypoint .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 ) // 14 (0xe) .maxstack 8 IL_0000: nop IL_0001: ldstr "Hello,Pronama!" IL_0006: call void [mscorlib]System.Console::WriteLine(string) IL_000b: nop IL_000c: nop IL_000d: ret } // end of method Pronama::Main
- .NET VBCPPEmit 19
- 20 Class Field public Foo private string X
- Roslyn etcGenerate Code Fix etcTransform / etcAnalyze 21
- Roslyn Roslyn 22
- Compiler APIs(Compiler Layer) RoslynAPI 23 Compiler APIs (Scripting APIs) Workspaces APIs(Services Layer) Features APIs(Editor Services Layer)
- Compiler APIs(Compiler Layer) RoslynAPI 24 Compiler APIs (Scripting APIs) Workspaces APIs(Services Layer) Features APIs(Editor Services Layer)
- Compiler APIs API 3 () 25
- Compiler APIs Microsoft.CodeAnalysis.dll Emit APISyntax Tree API () 26
- Compiler APIs Microsoft.CodeAnalysis.VisualBasic.dll Microsoft.CodeAnalysis.CSharp.dll 27
- Compiler APIs rcsc.exervbc.exe (Roslyn) VBCSCompiler.exe 28
- Compiler APIs API 29
- Compiler APIs Demo1 () 30 Dim tree = VisualBasicSyntaxTree.ParseText(code) Dim errors As New List(Of ErrorItem) For Each item In tree.GetDiagnostics errors.Add(New ErrorItem With {.Message = item.GetMessage, .Location = item.Location.SourceSpan.ToString, .Id = item.Id, .Severity = item.Severity.ToString}) Next
- Compiler APIs Demo1 () 31
- Compiler APIs Demo1 () () 32
- Compiler APIs Demo2 () Semantic Analysis 33 Dim tree = VisualBasicSyntaxTree.ParseText(code) Dim compilation = VisualBasicCompilation.Create("pronama", {tree}, {New MetadataFileReference(GetType(Object).Assembly.Location)}) Dim errors As New List(Of ErrorItem) For Each item In compilation.GetDiagnostics errors.Add(New ErrorItem With {.Message = item.GetMessage, .Location = item.Location.SourceSpan.ToString, .Id = item.Id, .Severity = item.Severity.ToString}) Next
- Compiler APIs Demo2 () 34
- Compiler APIs Demo2 () () () 35
- Compiler APIs Scripting APIs ( https://roslyn.codeplex.com/wikipage?title=FAQ#What happened to the REPL and hosting scripting APIs ) 36
- Compiler APIs(Compiler Layer) RoslynAPI 37 Compiler APIs (Scripting APIs) Workspaces APIs(Services Layer) Features APIs(Editor Services Layer)
- Workspace APIs API Microsoft.CodeAnalysis.Workspaces.dll Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll Microsoft.CodeAnalysis.CSharp.Workspaces.dll 38
- Workspace APIs (ex. ) ProjectSolution 39
- Workspace APIs 40 Dim workspace = MSBuild.MSBuildWorkspace.Create() Dim solution = Await workspace.OpenSolutionAsync(dlg.FileName) For Each projectId In solution.ProjectIds Dim project = solution.GetProject(projectId) Console.WriteLine("+ Project" + vbCrLf + " FileName: {0}, Lang: {1}, Id: {2}", project.Name, project.Language, project.Id.ToString) For Each docId In project.DocumentIds Dim document = project.GetDocument(docId) Console.WriteLine("- File" + vbCrLf + " Name: {0}, Path: {1}, ID: {2}", document.Name, document.FilePath, document.Id) Next Next
- Workspace APIs 41 Dim document = project.GetDocument(project.DocumentIds(0)) Dim version = Await document.GetTextVersionAsync() Dim text = Await document.GetTextAsync() Console.WriteLine("Version: {0}" + vbCrLf + Text: {1}" version.ToString , text.ToString) old = document Dim newDocument = Await Formatter.FormatAsync(document) Dim diff = Await newDocument.GetTextChangesAsync(old) version = Await newDocument.GetTextVersionAsync() text = Await newDocument.GetTextAsync() Console.WriteLine("Version: {0}" + vbCrLf + Text: {1}" version.ToString , text.ToString) For Each change In diff Console.WriteLine("*Change* + vbCrLf + "Place: {0}" + vbCrLf +"NewText: " , change.Span.ToString , change.NewText) Next
- Compiler APIs(Compiler Layer) RoslynAPI 42 Compiler APIs (Scripting APIs) Workspaces APIs(Services Layer) Features APIs(Editor Services Layer)
- Feature APIs Quick FixAPI Microsoft.CodeAnalysis.Features.dll NuGet Microsoft.CodeAnalysis.CodeActions 43
- Code Fix 44 VB() Code Fix
- Feature APIs Code Fix 45
- Roslyn Q&A 46
- DLR vs. Roslyn Dynamic Language Runtime() IronPythonIronRuby DLRRoslyn RoslynVisual Studio DLR 47
- DLR vs. Roslyn IL DLRSystem.Linq.Expressions RoslynEmit APIIL => 48
- DSL with Roslyn () RoslynAST 49
- Roslyn 50
- Roslyn 51 CTP 201110 Workspace APIScripting APICompiler API CTP2 20126 lock CTP3 20129 LINQ Preview 20144 async/await
- Roslyn Review and refine the design of the REPL window(scripting API). Discuss proposed language features. Remove the core compiler's dependency on the full .NET framework allowing the use of the Compilation data type on platforms like WinRT. ( http://roslyn.codeplex.com/wikipage?title=Roadmap&referringTitle=Documentation ) 52
- Roslyn IntelliSense () 53
- Roslyn C#/VB Roslyn End User Preview () https://roslyn.codeplex.com/wikipage?title=Language%20Feat ure%20Status&referringTitle=Documentation 54
- Roslyn MonoVB.NET () MonoNRefactoryMono.Csharp Mono Roslyn Compiler - Tracks Mono Patches https://github.com/mono/roslyn 55
- Roslyn ASP.NET vNextRoslyn Roslyn 56
- RoslynURL http://aka.ms/roslyn Roslyn Source Browser http://source.roslyn.codeplex.com/ .NET ("Roslyn") http://msdn.microsoft.com/ja-JP/roslyn 57
- Copyright 2014 bonprosoft All Rights Reserved. 58