0

假设 ProjectMain有对 Project 的引用Ref。在Main中,我定义了一个CSharpCodeProvider并使用它在运行时编译代码。

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.

在运行时编译的代码可能需要更新版本的 ProjectRef才能正确运行。所以我尝试Ref.Dll在相对子文件夹(plugins)中添加新的:

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

我还添加了以下内容:

AppDomain.CurrentDomain.AppendPrivatePath("plugins");  

问题是当我尝试动态编译脚本时,Ref.dll正在使用主文件夹中的并导致错误。

Ref那么,仅针对我的脚本引用新项目的最佳方式是什么?
PS 我真的更喜欢不必创建另一个 AppDomain,因为动态执行的代码与当前 AppDomain 中加载的代码相耦合,无法分离。

4

0 回答 0