我的一个项目中有以下代码片段,它从给定的 .cs 文件输出一个 .dll。
现在,我很想输出一个可移植类库而不是标准库,但不知道如何更改输出类型。
我读到输出类型只是 .csproj 的一部分,但我没有使用这种编译为 .dll 的方式的 .csproj。
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters cp = new CompilerParameters();
cp.OutputAssembly = "myassemblyname.dll";
cp.GenerateInMemory = false;
cp.IncludeDebugInformation = true;
CompilerResults cr = provider.CompileAssemblyFromFile(cp, new String[] { "MySourceFile.cs", codeFile });
if(cr.Errors.Count > 0) {
Console.WriteLine("Errors building {0}", cr.PathToAssembly);
foreach(CompilerError ce in cr.Errors) {
Console.WriteLine(" {0}", ce.ToString());
Console.WriteLine();
}
}
else
Console.WriteLine("Source {0} built into {1} successfully.", codeFile, cr.PathToAssembly);
}
任何人都知道如何指示 CSharpCodeProvider 输出可移植类库 (PCL)
最佳答案
根据 this回答,你应该只是pass the right assembly references到 CompilerParameters
和 set CompilerParameters.GenerateExecutable
属性设置为 false 以生成 dll。
要找出正确的引用,您可以通过 IDE 构建 PCL,然后查看“输出”窗口。
关于c# - PCL DomCompiler 可移植类库输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33740206/