使用 MSBuild 构建后运行测试时出现 MissingManifestResourceException(.mresource 在清单中具有路径)

发布于 2024-11-30 08:59:56 字数 1478 浏览 3 评论 0原文

我在使用命令行上的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光清浅 2024-12-07 08:59:56

看来将 LogicalName 添加到项目文件可以解决此问题:

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

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

<ItemGroup>
  <EmbeddedResource Include="Properties\Resources.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 文件,但该错误似乎仍然出现。

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="Properties\Resources.resx">
    <Generator>ResXFileCodeGenerator</Generator>
    <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    <LogicalName>$(RootNamespace).Properties.Resources.resources</LogicalName> 
  </EmbeddedResource>
</ItemGroup>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文