Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax Analysis with MS Roslyn

Tags:

c#

roslyn

I have a litle but stupid problem. I started working with MS Roslyn, and I am trying to do the Walkthrough, but directly at the beginning an error occurred...

error CS0117: 'Roslyn.Compilers.CSharp.SyntaxTree' does not contain a definition for 'ParseCompilationUnit'

I do not understand why it occurred... maybe one of you had the same problem.

My Sourceode:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Roslyn.Compilers;
using Roslyn.Compilers.CSharp;
using Roslyn.Services;
using Roslyn.Services.CSharp;

namespace gettingstarted2
{
    class Program
    {
        static void Main(string[] args)
        {
            SyntaxTree tree = SyntaxTree.ParseCompilationUnit(
                @"using System;
                using System.Collections;
                using System.Linq;
                using System.Text;

                namespace HelloWorld
                {
                    class Program
                    {
                        static void Main(string[] args)
                        {
                            Console.WriteLine(""Hello, World!"");
                        }
                    }
                }");

            var root = (CompilationUnitSyntax)tree.GetRoot();

        }
    }
}
like image 374
Anton Avatar asked Mar 03 '13 05:03

Anton


People also ask

What is Roslyn code analysis?

NET Compiler Platform (Roslyn) Analyzers inspect your C# or Visual Basic code for style, quality, maintainability, design, and other issues. This inspection or analysis happens during design time in all open files. Analyzers are divided into the following groups: Code style analyzers are built into Visual Studio.

Does Visual Studio use Roslyn?

NET compiler platform (Roslyn) package versions are supported for different versions of Visual Studio.

Why is Roslyn a compiler?

One advantage that Roslyn has is when your application needs a scripting interface. With Roslyn, you can directly compile the script as C# source code with same programming possibilities as the source of the application and directly use it. do you mean after compiling, the script is converted to C# source code?

What is Roslyn in .NET core?

Roslyn, the . NET Compiler Platform, empowers the C# compiler on . NET Core and allows developers to leverage the rich code analysis APIs to perform code generation, analysis and compilation.


1 Answers

What is the date mentioned in the walkthrough you were following? The method was renamed from ParseCompilationUnit to ParseText for the September CTP. If you a previous CTP installed, it's possible that the walkthrough wasn't updated properly when you installed the latest CTP.

I would recommend uninstalling and reinstalling the CTP or using repair.

like image 102
Kevin Pilch Avatar answered Sep 20 '22 17:09

Kevin Pilch