简体   繁体   English

PCL DomCompiler 可移植类库输出

[英]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.

相关问题 如何在可移植类库(PCL)中解码URL? - How to decode a URL in Portable Class Library (PCL)? 便携式类库(PCL)贡献 - 密码学 - Portable Class Library (PCL) Contrib - Cryptography 使用xamarin的目录类未显示在可移植类库(PCL)中 - Directory class not showing up in portable class library (PCL) using xamarin 无法在类库(Portable) - PCL中安装MvvmCross包 - Cannot install MvvmCross package in Class Library (Portable) - PCL 将Azure表存储引用到可移植类库(PCL)中 - Reference Azure Table Storage into a Portable Class Library (PCL) HttpUtility.ParseQueryString的可移植类库(PCL)版本 - Portable Class Library (PCL) Version Of HttpUtility.ParseQueryString 在(PCL)可移植类库中使用Windows.Networking - Using Windows.Networking in (PCL) Portable Class Library 使用便携式类库(PCL)从URL下载字符串 - Download string from URL using a portable class library (PCL) 如何列出PCL中的所有已加载程序集(可移植类库) - How to list all loaded assemblies in PCL (portable class library) 在Xamarin Forms可移植类库(PCL)中使用SOAP Web服务 - Consuming SOAP web service in Xamarin Forms Portable Class Library (PCL)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM