Mvc: MSB4018 The “GenerateEmbeddedResourcesManifest” task failed unexpectedly

Created on 20 Jul 2018  Â·  11Comments  Â·  Source: aspnet/Mvc

Description of the problem:

I am trying to add localization to my web app(using Aspnetcore 2.1.1 and Razor pages). However, the moment I add more than one .resx file, it fails to compile with following error.

Error   MSB4018 The "GenerateEmbeddedResourcesManifest" task failed unexpectedly.
System.InvalidOperationException: An item with the name '' already exists.
   at Microsoft.Extensions.FileProviders.Embedded.Manifest.Task.Internal.Entry.AddChild(Entry child)
   at Microsoft.Extensions.FileProviders.Embedded.Manifest.Task.Manifest.AddElement(String originalPath, String assemblyResourceName)
   at Microsoft.Extensions.FileProviders.Embedded.Manifest.Task.GenerateEmbeddedResourcesManifest.BuildManifest(EmbeddedItem[] processedItems)
   at Microsoft.Extensions.FileProviders.Embedded.Manifest.Task.GenerateEmbeddedResourcesManifest.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() Service C:\Users\.nuget\packages\microsoft.extensions.fileproviders.embedded\2.1.1\build\netstandard2.0\Microsoft.Extensions.FileProviders.Embedded.targets 65  

Version of Microsoft.Extensions.FileProviders.Embedded: 2.1.1 and Microsoft.AspNetCore.All: 2.1.1.

Possible cause of the issue

Problem is the content of generated manifest file "Microsoft.Extensions.FileProviders.Embedded.Manifest.xml". The manifest file generator adds this line for one *.resx file.
<File Name=""><ResourcePath></ResourcePath></File>. When the generator finds another *.resx file, it tries to add the same line to the manifest xml, and fails saying "An item with the name '' already exists."

investigate

Most helpful comment

Thanks for contacting us, @dudedev.
@ryanbrandenburg, can you please look into this? Thanks!

All 11 comments

Thanks for contacting us, @dudedev.
@ryanbrandenburg, can you please look into this? Thanks!

@dudedev could you create a minimal reproduction app which displays this behavior? This guarantees that we're looking at the same problem you're having.

@ryanbrandenburg I have created a sample app with the problem. How do you want me to share the source code?

@ryanbrandenburg Steps to reproduce:

  1. Create a wepapp using template "ASP.NET Core Web Application"
  2. Edit .csproj file to include <GenerateEmbeddedFilesManifest>True</GenerateEmbeddedFilesManifest> under <PropertyGroup>.
  3. Add two resources files e.g. Resources.en.resx and Resources.de.resx
  4. Build the project, you should see the build error

@dudedev, please share it as a public repo in GitHub?

Thanks @dudedev.
@ryanbrandenburg, its all yours now!

Thanks @dudedev, this did end up replicating. I was able to track the failure down to this area in aspnet/FileSystem. It seems that that task is not very robust, and makes the assumption that EmbeddedResource.LogicalName will always have a value. This is not the case for the default EmbeddedResources created for .resx files.

@mkArtakMSFT who knows that area the best? It looks like @javiercn did some work in there but I don't know if he's a SME who would be best situated to fix this.

@dudedev, in the mean time it's not ideal, but you can both generate your embedded files manifest and have these resx files embedded by setting <EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems> in your propertyGroup and doing something like

<ItemGroup>
    <EmbeddedResource Include="Resources/Resource.de-DE.resx">
      <LogicalName>Resources/Resource.de-DE.resx</LogicalName>
    </EmbeddedResource>
    <EmbeddedResource Include="Resources/Resource.en-US.resx">
      <LogicalName>Resources/Resource.en-US.resx</LogicalName>
    </EmbeddedResource>
</ItemGroup>

to manually embed the resources.

I’m the right person to look at this. This is a patch candidate I think. @natemcmaster sorry for ruining your day :(

Thanks @ryanbrandenburg.
@javiercn, can you please look into this further and confirm whether this will be a patch candidate or not.

@dudedev I can't reproduce this with my version of the SDK. I think this was caused by a change in the definition of the EmbeddedResource made in the SDK (which change, I don't know for sure). In any case, I think this is a transient issue. You can exclude the resource files from the manifest as exemplified below and that should fix the problem:

<ItemGroup>
    <EmbeddedResource Include="Resources/Resource.de-DE.resx">
      <LogicalName>Resources/Resource.de-DE.resx</LogicalName>
      <ExcludeFromManifest>true</ExcludeFromManifest>
    </EmbeddedResource>
    <EmbeddedResource Include="Resources/Resource.en-US.resx">
      <LogicalName>Resources/Resource.en-US.resx</LogicalName>
      <ExcludeFromManifest>true</ExcludeFromManifest>
    </EmbeddedResource>
</ItemGroup>

I'm closing the issue as there no more action to take from us at this point.
@dudedev If this doesn't solve your issue let us know.

Thanks for bringing this up.

Was this page helpful?
0 / 5 - 0 ratings