L
Luis Arvayo
I am compiling and executing c# code at runtime and I need to define in
CompilerParameters.ReferencedAssemblies one of my own assemblies together
with the standard System.dll u others.
Example:
// compiler options
System.CodeDom.Compiler.CompilerParameters options = new
System.CodeDom.Compiler.CompilerParameters();
options.GenerateExecutable = false; // result is a dll
options.GenerateInMemory = true;
//options.CompilerOptions = "/target:library";
options.MainClass = "MyClass";
options.ReferencedAssemblies.AddRange(new string[]{"System.dll",
"System.Data.dll",
System.Windows.Forms.Application.StartupPath + @"\MyAssembly.dll"});
********
options.IncludeDebugInformation = false;
// create the compilker
ICodeCompiler compiler = (new
Microsoft.CSharp.CSharpCodeProvider()).CreateCompiler();
// build and look for compiler errors
System.CodeDom.Compiler.CompilerResults result =
compiler.CompileAssemblyFromSource(options, source.ToString());
From the above code, on the line highlighted (*) if I don't define the
Application.StartupPath as the directory where to found my own assembly, the
"File not found" exception is thrown.
But that fact forces me to always define the location of the assembly as
same as the application startup path (where the main .exe resides).
The above code belongs also to other assembly used in applications and not
the application per se. So, that assembly is tied to reference the other
assembly used, with that path.
Then the question is: how can I do in order to avoid the path dependency of
the referenced assembly as described above ?
Thanks in advance.
Luis Arvayo
CompilerParameters.ReferencedAssemblies one of my own assemblies together
with the standard System.dll u others.
Example:
// compiler options
System.CodeDom.Compiler.CompilerParameters options = new
System.CodeDom.Compiler.CompilerParameters();
options.GenerateExecutable = false; // result is a dll
options.GenerateInMemory = true;
//options.CompilerOptions = "/target:library";
options.MainClass = "MyClass";
options.ReferencedAssemblies.AddRange(new string[]{"System.dll",
"System.Data.dll",
System.Windows.Forms.Application.StartupPath + @"\MyAssembly.dll"});
********
options.IncludeDebugInformation = false;
// create the compilker
ICodeCompiler compiler = (new
Microsoft.CSharp.CSharpCodeProvider()).CreateCompiler();
// build and look for compiler errors
System.CodeDom.Compiler.CompilerResults result =
compiler.CompileAssemblyFromSource(options, source.ToString());
From the above code, on the line highlighted (*) if I don't define the
Application.StartupPath as the directory where to found my own assembly, the
"File not found" exception is thrown.
But that fact forces me to always define the location of the assembly as
same as the application startup path (where the main .exe resides).
The above code belongs also to other assembly used in applications and not
the application per se. So, that assembly is tied to reference the other
assembly used, with that path.
Then the question is: how can I do in order to avoid the path dependency of
the referenced assembly as described above ?
Thanks in advance.
Luis Arvayo