0

Suppose Project Main has a reference to Project Ref. In Main, I have defined a CSharpCodeProvider and use it to compile code at runtime.

var provider = new CSharpCodeProvider(new Dictionary<string, string> { { "CompilerVersion", "v4.0" } });
var parameters = new CompilerParameters();
parameters.ReferencedAssemblies.Add("System.dll");
// Rest of the referenced assemblies.

The code which is compiled at runtime, might require a newer version of Project Ref to run correctly. So I tried to add the new Ref.Dll in a relative subfolder (plugins):

    parameters.ReferencedAssemblies.Add(@"d:\project-output-path\plugins\Ref.dll");  

I have also added the following:

AppDomain.CurrentDomain.AppendPrivatePath("plugins");  

Problem is when I try to compile the script dynamically, the Ref.dll in the main folder is being used and causes error.

So, What would be the best way to reference the new Ref project only for my script?
P.S. I really prefer not having to create another AppDomain since the dynamically executing code is coupled with the code loaded in current AppDomain and cannot be separated.

Kamyar
  • 18,639
  • 9
  • 97
  • 171
  • That makes little sense, surely you have a problem when you *run* the code. You already know what to do about it. – Hans Passant Nov 22 '14 at 15:52
  • problem is when I compile new code in runtime, I'd like to have the new `Ref` project as reference which is newer than the one referenced in project `Main`. The old `Ref` reference will be used to compile my script in runtime which causes errors. My question is about finding a way to isolate references in my CodeProvider paramaters and use the new `Ref` project. – Kamyar Nov 22 '14 at 15:53
  • Also to be more clear, the code which is being compiled at runtime can vary (so can the version of `Ref` project needed to be referenced in runtime). Basically I'd like to add a new version of a referenced assembly (which resides in a sub-folder) as a reference to my CodeProvider's referenced assemblies in runtime. – Kamyar Nov 22 '14 at 15:58

0 Answers0