简体   繁体   中英

Syntax Analysis with MS 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();

        }
    }
}

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.

@Anton to be shure, that is the newest one... You can use Nuget to install Roslyn.

Run the following command in the Package Manager Console : PM> Install-Package Roslyn

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM