C#CSharp编译器程序集无法导入任何内容

C#CSharp编译器程序集无法导入任何内容,c#,csharpcodeprovider,C#,Csharpcodeprovider,我一直在尝试向服务器应用程序添加命令系统 问题是:command.cs文件不在项目内,但 它们是从运行时的另一个文件夹编译的,不能包含任何内容。 编译器代码: static CompilerResults Compile(String path) { var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" }


我一直在尝试向服务器应用程序添加命令系统
问题是:command.cs文件不在项目内,但
它们是从运行时的另一个文件夹编译的,不能包含任何内容。

编译器代码:

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);
        }
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());
            }
        }
    }
}
在本部分:

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" } });
var csc=new CSharpCodeProvider(new Dictionary(){{“compilervision”,“v3.5”});
您告诉编译器使用.net Framework版本3.5,该版本不包含一些较新的功能,例如System.Threading.Tasks。添加更高版本号,例如4.0或更高版本:

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

Hi,您知道如何将项目中的命名空间包含到CSharpCodeProvider中吗?
var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v4.0" } });