如何通过 roslyn 添加 "copy local" true 的引用?

How to add reference with "copy local" true via roslyn?

我正在尝试使用以下语法通过 roslyn 添加对我的 VB.NET 项目的元数据引用:

project = project.AddMetadataReference(
    MetadataReference.CreateFromFile(
        package.FullName,
        MetadataReferenceProperties.Assembly));

但是,我需要将此程序集的 "Copy local" 设置为 true,该怎么做?似乎对于程序集参考我只有 WithEmbedInteropTypesWithAliases 可用,如何设置特定参考的其余属性...?

我怀疑 "copy local" 是一个 MSBuild 功能,而不是 编译器 功能。如果您查看 csc 命令行:

                        - INPUT FILES -
 /recurse:<wildcard>           Include all files in the current directory and
                               subdirectories according to the wildcard
                               specifications
 /reference:<alias>=<file>     Reference metadata from the specified assembly
                               file using the given alias (Short form: /r)
 /reference:<file list>        Reference metadata from the specified assembly
                               files (Short form: /r)
 /addmodule:<file list>        Link the specified modules into this assembly
 /link:<file list>             Embed metadata from the specified interop
                               assembly files (Short form: /l)
 /analyzer:<file list>         Run the analyzers from this assembly
                               (Short form: /a)
 /additionalfile:<file list>   Additional files that don't directly affect code
                               generation but may be used by analyzers for produ
cing
                               errors or warnings.

您可以 /reference:<alias>=<file> 获取别名,或 /link:<file list> 嵌入互操作元数据,但是 此处 到 "copy local" 没有选项.

您必须自己执行复制。