Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

c# - MissingManifestResourceException when running tests after building with MSBuild (.mresource has path in manifest)

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 PropertiesResources.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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...