run time compilation
От: fyn85  
Дата: 21.06.07 13:40
Оценка:
Помогите с проблемой.
Есть код,
using System.IO;
using System.Data.SqlClient;

public class t
{
    public static void test()
    {
    }
}


При попытке компиляции его с помощью кода

        CompilerParameters options = new CompilerParameters(new string[] { Assembly.GetExecutingAssembly().Location });
        options.GenerateInMemory = true;
        CSharpCodeProvider provider = new CSharpCodeProvider();
        compiler = provider.CreateCompiler();
        CompilerResults results = compiler.CompileAssemblyFromSource(options, script);


Выдаеться ошибка :
The type or namespace name 'Data' does not exist in the namespace 'System' (are you missing an assembly reference?)

Причем System.IO хавает, как заставить его скушать System.Data, как добавлять в таком случае reference?
Зврвнее благодарен.
Re: run time compilation
От: mrozov  
Дата: 21.06.07 13:51
Оценка:
Здравствуйте, fyn85, Вы писали:

F>Выдаеться ошибка :

F>The type or namespace name 'Data' does not exist in the namespace 'System' (are you missing an assembly reference?)

F>Причем System.IO хавает, как заставить его скушать System.Data, как добавлять в таком случае reference?

F>Зврвнее благодарен.

Ну прямо в MSDN-е же пример:

    CompilerParameters cp = new CompilerParameters();

    // Generate an executable instead of 
    // a class library.
    cp.GenerateExecutable = true;

    // Set the assembly file name to generate.
    cp.OutputAssembly = exeFile;

    // Generate debug information.
    cp.IncludeDebugInformation = true;

    // Add an assembly reference.
    cp.ReferencedAssemblies.Add( "System.dll" );
    // Save the assembly as a physical file.
    cp.GenerateInMemory = false;

    // Set the level at which the compiler 
    // should start displaying warnings.
    cp.WarningLevel = 3;

    // Set whether to treat all warnings as errors.
    cp.TreatWarningsAsErrors = false;
    
    // Set compiler argument to optimize output.
    cp.CompilerOptions = "/optimize";
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.