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
Microsoft.Extensions.FileProviders.Embedded: 2.1.1 and Microsoft.AspNetCore.All: 2.1.1.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."
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:
<GenerateEmbeddedFilesManifest>True</GenerateEmbeddedFilesManifest> under <PropertyGroup>.@dudedev, please share it as a public repo in GitHub?
@mkArtakMSFT https://github.com/dudedev/MSB4018
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.
Most helpful comment
Thanks for contacting us, @dudedev.
@ryanbrandenburg, can you please look into this? Thanks!