[英]PCL DomCompiler Portable Class Library output
I have below code snippet in one of my projects, which outputs a .dll from a given .cs file.我在我的一个项目中有以下代码片段,它从给定的 .cs 文件输出一个 .dll。
Now, I would love to output a portable class library instead of a standard library, yet have no idea how to change the output type.现在,我很想输出一个可移植的类库而不是标准库,但不知道如何更改输出类型。
I read the output type is just part of the .csproj, but I don't have a .csproj with this way of compiling to .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);
}
Anyone have an idea howto instruct CSharpCodeProvider to output a Portable Class Library (PCL)任何人都知道如何指示 CSharpCodeProvider 输出可移植类库 (PCL)
According to this answer, you should just pass the right assembly references to CompilerParameters
and set CompilerParameters.GenerateExecutable
property to false to generate dll.根据此答案,您应该将正确的程序集引用传递给CompilerParameters
并将CompilerParameters.GenerateExecutable
属性设置为 false 以生成 dll。
To figure out the right references, you can build PCL via IDE and just look to Output window.要找出正确的引用,您可以通过 IDE 构建 PCL,然后查看输出窗口。
In the end, we switched this particular project's build method where it now just follows a .csproj.最后,我们切换了这个特定项目的构建方法,现在它只遵循 .csproj。 But our tests with adding the correct CompilerParameters.ReferencedAssemblies seemed to work, so marked as answer.但是我们添加正确的 CompilerParameters.ReferencedAssemblies 的测试似乎有效,因此标记为答案。
20:20-hindsight-remark: Generating the code and asking build to compile a project does seem less of a headache now.. pointy clicky interfaces aren't so bad after all. 20:20-事后评论:生成代码并要求构建来编译项目现在似乎不那么令人头疼了.. 尖尖的可点击界面毕竟不是那么糟糕。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.