2016-04-02 11 views
1


サーバーアプリケーションにコマンドシステムを追加しようとしてアイブ
問題があります。プロジェクト内ではなく、
が、彼らは上の別のフォルダからコンパイルされているコマンドは.csファイルランタイムは何もincudeすることはできません。
C#のcsharpcompilerコンパイラアセンブリは、何もインポートすることはできません

コンパイラコード:

static CompilerResults Compile(String path) 
     { 
      var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } }); 
      var parameters = new CompilerParameters(new[] { "mscorlib.dll", "System.Core.dll" }, "DS Server.exe", true); 
      parameters.GenerateExecutable = true; 
      return csc.CompileAssemblyFromFile(parameters, path); 
     } 

外部の.csコードファイル:

using DS_Server; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net.Sockets; 
using System.Reflection; 
using System.Text; 
using System.Threading.Tasks; 

namespace JMnet 
{ 
    class command 
    { 
     public void run(TcpListener server,Dictionary<String,user> users , Dictionary<String, Assembly> Commands, String[] args) 
     { 
      foreach (user usr in users) { 
       var IP = ((IPEndPoint)usr.getClient().Client.RemoteEndPoint).Address.ToString(); 
       Core.Log.Geneic("Players",IP+" is connected as "+usr.getName()+", ping: "+usr.getPing().ToString()); 
      } 
     } 
    } 
} 

エラー:

server started 
Starting C-Sys 1.0 
Found 2 commands to register 
compiling kick 
[Compiler]: c: \ csys \ cmd \ kick.cs (1,7): error CS0246: The type or namespace name DS_Server not found (missing a using statement or assembly reference?) 
[Compiler]: c: \ csys \ cmd \ kick.cs (5,14): error CS0234: The type or namespace name just does not exist in the namespace System (missing an assembly reference?) 
[Compiler]: c: \ csys \ cmd \ kick.cs (8,24): error CS0234: The type or name of the Tasks namespace does not exist in the namespace System.Threading (missing an assembly reference?) 
[Compiler]: c: \ csys \ cmd \ kick.cs (14,25): error CS0246: The type or namespace name TcpListener not found (missing a using statement or assembly reference?) 
[Compiler]: c: \ csys \ cmd \ kick.cs (14,62): error CS0246: The type or namespace name user is not found (missing a using statement or assembly reference?) 
Registered kick 
compiling players 
[Compiler]: c: \ csys \ cmd \ players.cs (1,7): error CS0246: The type or namespace name DS_Server not found (missing a using statement or assembly reference?) 
[Compiler]: c: \ csys \ cmd \ players.cs (5,14): error CS0234: The type or namespace name just does not exist in the namespace System (missing an assembly reference?) 
[Compiler]: c: \ csys \ cmd \ players.cs (8,24): error CS0234: The type or name of the Tasks namespace does not exist in the namespace System.Threading (missing an assembly reference?) 
[Compiler]: c: \ csys \ cmd \ players.cs (14,25): error CS0246: The type or namespace name TcpListener not found (missing a using statement or assembly reference?) 
[Compiler]: c: \ csys \ cmd \ players.cs (14,62): error CS0246: The type or namespace name user is not found (missing a using statement or assembly reference?) 
Registered player 

答えて

2
この部分で

var parameters = new CompilerParameters(new[] { "mscorlib.dll", "System.Core.dll" }, "DS Server.exe", true); 

あなたはコンパイラが見つからないすべてのタイプが宣言されているアセンブリを追加する必要があります。 mscorlib.dllとSystem.Core.dllのみをインクルードしますが、コンパイルされたコードで使用する必要がある他のアセンブリもすべて含める必要があります。

これは、例えば次のようになります。

var parameters = new CompilerParameters(new[] { "mscorlib.dll", "System.Core.dll", "System.dll", "DS_Server.dll" }, "DS Server.exe", true); 

、あなたがアセンブリのリストを指定する場所をコンパイルしたい* .csファイルのファイル以外の設定ファイルを置く、アセンブリが必要とされているものを、事前に知ることができない場合ロードする。

ここでまた

、:

var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } }); 

あなたが例えばSystem.Threading.Tasksのようないくつかの新しい機能が含まれていません.NET Frameworkのバージョン3.5を使用するようにコンパイラに指示。例えば、4.0以上のためのような高いバージョン番号を追加します。

var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v4.0" } }); 
+0

は今、これをしようと、高速応答に感謝 –

+0

これはこんにちは、あなたはCSharpCodeProviderにプロジェクト内の名前空間を含める方法を知っている私のため –

+0

働いていましたか? – Adib

関連する問題