使用 MSBuild 构建后运行测试时出现 MissingManifestResourceException(.mresource 在清单中具有路径)
我在使用命令行上的 MSBuild 构建服务器上的 C# 项目的嵌入式资源时遇到问题。在 Visual Studio 中构建和运行测试时,该项目工作得很好,但是当从命令行运行 MSBuild 时,我在运行测试时遇到以下问题:
System.Resources.MissingManifestResourceException:找不到任何适合指定区域性或中立文化。确保“.Properties.Resources.resources”在编译时正确嵌入或链接到程序集“”,或者所需的所有附属程序集均可加载并完全签名。
System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(String fileName) at System .Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo文化,字典`2 localResourceSets,布尔tryParents,布尔createIfNotExists,StackCrawlMark&stackMark)在System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestCulture,布尔createIfNotExists,布尔tryParents,StackCrawlMark&stackMark)在System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo文化,布尔) createIfNotExists, Boolean tryParents) at System.Resources.ResourceManager.GetString(String name, CultureInfoculture) at Properties.Resources.get_SomeResource() in \Properties\Resources.Designer.cs:line 87
我已将问题跟踪到生成的 IL (我使用 ildasm)。在 Visual Studio 中进行构建时,会在程序集的清单中设置以下内容:
.mresource public <PROJECTNAME>.Properties.Resources.resources
{
// Offset: 0x00000000 Length: 0x00000236
}
但是当使用 MSBuild 进行构建时,会生成以下输出:
.mresource public '../..//Build/<PROJECTNAME>_AnyCPU_Debug_Obj/<PROJECTNAME>.Properties.Resources.resources'
{
// Offset: 0x00000000 Length: 0x00000236
}
可以看到,资源的路径突然成为资源名称的一部分。
有谁知道如何解决这个问题?
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: 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(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 \Properties\Resources.Designer.cs:line 87
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
}
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来将 LogicalName 添加到项目文件可以解决此问题:
即项目文件中的嵌入资源条目如下所示:
详细信息请参阅: http://blogs.msdn。 com/b/msbuild/archive/2007/10/19/manifest-resource-names-changed-for-resources-files.aspx
请注意,我们正在使用.resx 文件,但该错误似乎仍然出现。
It appears adding LogicalName to the project file fixes it:
i.e. so the embedded resource entry in the project file looks like this:
This is detailed in: http://blogs.msdn.com/b/msbuild/archive/2007/10/19/manifest-resource-names-changed-for-resources-files.aspx
Note that we are using a .resx file, but the bug still appears to occur.