【问题标题】:Including an embedded resource in a compilation made by Roslyn在 Roslyn 制作的编译中包含嵌入式资源
【发布时间】:2015-01-07 04:39:59
【问题描述】:

我正在尝试将嵌入式资源包含到我正在使用 Roslyn 编译的 dll 中。我找到了一些帮助我走上正轨的东西here.

但是,当我使用以下代码创建 dll 时:

const string resourcePath = @"C:\Projects\...\Properties\Resources.resources";
var resourceDescription = new ResourceDescription(
                    "Resources.resources",
                    () => File.OpenRead(resourcePath),
                    true);

var result = mutantCompilation.Emit(file, manifestResources: new [] {resourceDescription});   

我发现它将通过我为项目创建的所有单元测试,除了那些依赖资源文件的单元测试。

我得到的错误如下所示:

System.Resources.MissingManifestResourceException ... Make sure "[Project].Properties.Resources.resources" was correctly embedded or linked into      
assembly "[Project]" at compile time, or that all the satellite assemblies required are loadable and fully signed.

dll 应该是经过签名的,当它由 roslyn 发出时,它会带有正确的公钥。此外,Resource.resx 直接包含在我的项目的 Properties 文件夹中。

如果有人能提供任何帮助,我将不胜感激。

【问题讨论】:

  • 编辑了我的问题以反映我所做的更多研究。
  • 当我尝试点击您在第一段中提供的链接时,我收到“您无权执行此操作”。我想你不记得它的全部内容了吗?

标签: c# embedded-resource roslyn


【解决方案1】:

好的,所以当我在寻找答案时,我遇到了this web page,其中评论说资源流为空,直到他添加了命名空间。

所以在添加命名空间后我得到了这样的结果

const string resourcePath = @"C:\Projects\...\Properties\Resources.resources";
var resourceDescription = new ResourceDescription(
                "[namespace].Resources.resources",
                () => File.OpenRead(resourcePath),
                true);

var result = mutantCompilation.Emit(file, manifestResources: new [] {resourceDescription}); 

它的运行完全符合您的预期。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 2019-03-28
    • 1970-01-01
    • 2011-10-30
    • 2021-02-09
    • 1970-01-01
    相关资源
    最近更新 更多