I have an asp.net core project with the following properties:
- filename: WebApi.csproj
- Rootnamespace: Cmp.WebApi.csproj
- AssemblyName: (not set)
I'm trying to use asp.net localization, but the resourcemanager cannot locate the language resources. The docs provide some answer:
If the root namespace of an assembly is different than the assembly name:
- Localization does not work by default.
- Localization fails due to the way resources are searched for within the assembly. RootNamespace is a build-time value which is not available to the executing process. If the RootNamespace is different from the AssemblyName, include the following in AssemblyInfo.cs (with parameter values replaced with the actual values):
using System.Reflection; using Microsoft.Extensions.Localization; [assembly: ResourceLocation("Resource Folder Name")] [assembly: RootNamespace("App Root Namespace")]
The problem is that in .net core 5 there is no longer an assemblyInfo.cs file but its being autogenerated. This means i'd need to add RootNamespace
to the .csproj file somehow.
How can i do this?
EDIT I've tried adding:
<ItemGroup>
<AssemblyMetadata Include="ResourceLocation" Value="Resources" />
<AssemblyMetadata Include="RootNamespace" Value="Cmp.WebApi" />
</ItemGroup>
To the .csproj file but that did not work - it generated the following assemblyInfo in obj
[assembly: System.Reflection.AssemblyMetadata("ResourceLocation", "Resources")]
[assembly: System.Reflection.AssemblyMetadata("RootNamespace", "OPG.WebApi")]
Also note that this works fine if the RootNameSpace is the same as the assemblyname.
EDIT 2
I've also tried:
<PropertyGroup>
<AssemblyResourceLocation>Resources</AssemblyResourceLocation>
<AssemblyRootNamespace>Cmp.WebApi</AssemblyRootNamespace>
</PropertyGroup>
But that did not work aswell, which seems logical considering that i don't see those properties in the msbuild task: