c# - PCL DomCompiler 可移植类库输出

标签 c#

我的一个项目中有以下代码片段,它从给定的 .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 referencesCompilerParametersset CompilerParameters.GenerateExecutable 属性设置为 false 以生成 dll。

要找出正确的引用,您可以通过 IDE 构建 PCL,然后查看“输出”窗口。

关于c# - PCL DomCompiler 可移植类库输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33740206/

相关文章:

c# - 问题复制 C# 枚举器接口(interface)

c# - 可靠的发布/订阅

c# - 将 XSD 文件转换为 C# 可序列化类

c# - 如何在 Monotouch 中绑定(bind) NSObject<EAAccessoryDe​​legate>?

c# - 如何启用/禁用防火墙?

c# - 如何向ffmpeg提供登录用户名和密码?

c# - 使用 XmlSerializer 序列化 IntPtr

c# - 了解 Mediatr 的 Autofac 配置

c# - 使用相同的 XML 注释记录重载方法

c# - AntiForgery token 中的有效字符 __RequestVerificationToken