使用 MSBuild 构建后运行测试时出现 MissingManifestResourceException(.mresource 在清单中有路径) [英] MissingManifestResourceException when running tests after building with MSBuild (.mresource has path in manifest)

查看:19
本文介绍了使用 MSBuild 构建后运行测试时出现 MissingManifestResourceException(.mresource 在清单中有路径)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在命令行上使用 MSBuild 的构建服务器上的 C# 项目的嵌入式资源存在问题.该项目在 Visual Studio 中构建和运行测试时运行良好,但是从命令行运行 MSBuild 时,运行测试时出现以下问题:

I am having a problem with embedded resources for a C# project on a build server using MSBuild on the command line. The project works just fine when building and running tests in Visual Studio, but when running MSBuild from the command line I get the following problems when running a test:

System.Resources.MissingManifestResourceException:找不到任何适合指定区域性或中性区域性的资源.确保.Properties.Resources.resources"在编译时被正确嵌入或链接到程序集"中,或者所有需要的附属程序集都是可加载的并且是完全签名的..

System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture. Make sure ".Properties.Resources.resources" was correctly embedded or linked into assembly "" at compile time, or that all the satellite assemblies required are loadable and fully signed..

System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(String fileName) at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfoculture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark & stackMark) at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark) at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfoculture, Boolean createIfNotExists, Boolean tryParents) at System.Resources.ResourceManager.GetString(String name, CultureInfoculture) at Properties.ResourcesPropertiesResources.Designer.cs:第 87 行中的 .get_SomeResource()

System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(String fileName) at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark) at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark) at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents) at System.Resources.ResourceManager.GetString(String name, CultureInfo culture) at Properties.Resources.get_SomeResource() in PropertiesResources.Designer.cs:line 87

我已将问题追溯到生成的 IL(我使用 ildasm).在 Visual Studio 中构建时,在程序集的清单中设置以下内容:

I have tracked the problem down into the generated IL (I use ildasm). When bulding in Visual Studio, the following is set in the manifest of the assembly:

.mresource public <PROJECTNAME>.Properties.Resources.resources
{
  // Offset: 0x00000000 Length: 0x00000236
}

但是在使用 MSBuild 构建时会生成以下输出:

but when building using MSBuild the following output is generated:

.mresource public '../..//Build/<PROJECTNAME>_AnyCPU_Debug_Obj/<PROJECTNAME>.Properties.Resources.resources'
{
  // Offset: 0x00000000 Length: 0x00000236
}

正如人们所看到的那样,资源的路径突然成为资源名称的一部分.

as one can see the path to the resource is suddenly part of the resource name.

有人知道如何解决这个问题吗?

Does anyone have any ideas how to fix this?

推荐答案

似乎将 LogicalName 添加到项目文件中修复了它:

It appears adding LogicalName to the project file fixes it:

<LogicalName>$(RootNamespace).Properties.Resources.resources</LogicalName> 

即因此项目文件中嵌入的资源条目如下所示:

i.e. so the embedded resource entry in the project file looks like this:

<ItemGroup>
  <EmbeddedResource Include="PropertiesResources.resx">
    <Generator>ResXFileCodeGenerator</Generator>
    <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    <LogicalName>$(RootNamespace).Properties.Resources.resources</LogicalName> 
  </EmbeddedResource>
</ItemGroup>

详细说明如下:http://blogs.msdn.com/b/msbuild/archive/2007/10/19/manifest-resource-names-changed-for-resources-files.aspx

请注意,我们使用的是 .resx 文件,但该错误似乎仍然存在.

Note that we are using a .resx file, but the bug still appears to occur.

这篇关于使用 MSBuild 构建后运行测试时出现 MissingManifestResourceException(.mresource 在清单中有路径)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆