2013-03-03 63 views
6

我有一個小問題但很愚蠢的問題。我開始與MS羅斯林的工作,而我試圖做演練,而是直接在發生錯誤的開始......使用MS Roslyn進行語法分析

錯誤CS0117:「Roslyn.Compilers.CSharp.SyntaxTree」不包含 'ParseCompilationUnit'的定義

我不明白它爲什麼會發生......也許你們中的一個人有同樣的問題。

我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(); 

     } 
    } 
} 
+0

我認爲這是演練的一個問題。改爲使用'ParseText'。 – 2013-03-03 07:08:19

回答

5

是什麼日子在你下面的演練中提到?對於9月份CTP,該方法從ParseCompilationUnit更名爲ParseText。如果您安裝了以前的CTP,則安裝最新的CTP時可能未正確更新漫遊。

我會建議卸載並重新安裝CTP或使用修復。

+0

謝謝凱文!那是我正在尋找的信息!有趣的是,我沒有發現任何有關重命名......甚至爲此目的,我使用http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx的在線版本舒適,那就是最新的...但不是不是,它是從2012年6月開始,在安裝目錄中是指向2012年9月的指南,其中ParseText代替了ParseCompilationUnit。 – Anton 2013-03-04 01:43:18

+0

感謝您的指點,我將努力讓網上的更新! – 2013-03-04 03:06:06

0

@安頓舒服,這是最新的...你可以使用Nuget來安裝Roslyn。

運行的軟件包管理器控制檯執行以下命令:PM>安裝,包裝羅斯林

0

安裝,包裝羅斯林

安裝,包裝:無法找到包「羅斯林」 在行:1個字符: 2 +安裝包Roslyn + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:NotSpecified:(:) [Install-Package],Exception + FullyQualifiedErrorId :NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

PM>