Microsoft Ignite NZ 25-28 October 2016 SKYCITY, Auckland
The Power of Roslyn: Improving Your Productivity with Live Code Analyzers Kasey Uhlenhuth Program Manager .NET & Visual Studio @kuhlenhuth
Agenda Introduce Roslyn Demonstrate Analyzers 4/6/2019 10:23 AM Agenda Introduce Roslyn Demonstrate Analyzers Build an Analyzer (using in-progress IOperation) Explore Analyzer Ecosystem © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
http://roslyn.io @roslyn Microsoft Ignite 2016 4/6/2019 10:23 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Microsoft Ignite 2016 4/6/2019 10:23 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
1 2 Write new features faster Provide open source API Microsoft Ignite 2016 4/6/2019 10:23 AM 1 Write new features faster 2 Provide open source API © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
1 Write new features faster Microsoft Ignite 2016 4/6/2019 10:23 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Tuples Easily pass around groups of values
Pattern matching Test the shape and content of expressions
Local functions Clean up classes by nesting helpers
2 Provide open source API Microsoft Ignite 2016 4/6/2019 10:23 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Microsoft Ignite 2016 4/6/2019 10:23 AM Analyzers identify errors and provide fixes in your code as you type, i.e. without having to wait for a build. © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Demo Microsoft Ignite 2016 4/6/2019 10:23 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Analyzer Severities Editor Treatment Build Consequence In Error List Microsoft Ignite 2016 4/6/2019 10:23 AM Analyzer Severities Editor Treatment Build Consequence In Error List Error Breaks Yes Warning None Suggestion No © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
VSIX NUGET Microsoft Ignite 2016 4/6/2019 10:23 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Teach new language features/concepts Introduce best practices for SDK Enforce code style rules Identify errors before build 4/6/2019 10:23 AM © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Syntax and Semantic APIs 4/6/2019 10:23 AM Syntax and Semantic APIs Syntax Tree High-fidelity representation of source code Semantic Model Answers semantic questions about syntax IOperation In-progress evolution of Roslyn APIs Provides semantic information Abstracts over common syntactic shapes Common representation for C#/VB Syntax Generator Can generate source code for both C# and VB © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Let’s write an analyzer! 4/6/2019 10:23 AM Let’s write an analyzer! var a = new int[0]; var a = Array.Empty<int>(); © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Diagnostic Code Fix Microsoft Ignite 2016 4/6/2019 10:23 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Demo Microsoft Ignite 2016 4/6/2019 10:23 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
4/6/2019 10:23 AM Analyzer Ecosystem FxCopAnalyzers (MSFT): https://www.nuget.org/packages/Microsoft.CodeAnalysis.FxCopAnalyzers/ SonarLint http://www.sonarlint.org/visualstudio/rules/index.html StyleCopAnalyzers: https://github.com/DotNetAnalyzers/StyleCopAnalyzers CodeCracker https://github.com/code-cracker/code-cracker Roslynator https://github.com/JosefPihrt/Roslynator VS Refactoring Essentials: http://vsrefactoringessentials.com/ GCop: https://visualstudiogallery.msdn.microsoft.com/f082f20e-5123-4c0d-975a-0a17995d858b © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Call to Action Write an analyzer! Explore what is in the ecosystem 4/6/2019 10:23 AM Call to Action Write an analyzer! https://github.com/dotnet/roslyn/wiki/Getting-Started-Writing-a-Custom-Analyzer-&-Code-Fix Explore what is in the ecosystem kaseyu@microsoft.com @kuhlenhuth © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Related Sessions C# and Visual Basic Code-focused Development with Visual Studio “15” [M380]
4/6/2019 10:23 AM © 2014 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.