C
C#2mo ago
Lenon

.resx does not properly generate Design-File

Looking at AspNetCore Identity (or the whole aspnetcore logic), we can see, that their ErrorDescribers access the resource like:
<data name="UserNotInRole" xml:space="preserve">
<value>User is not in role '{0}'.</value>
<comment>Error when a user is not in the role</comment>
</data>
<data name="UserNotInRole" xml:space="preserve">
<value>User is not in role '{0}'.</value>
<comment>Error when a user is not in the role</comment>
</data>
This will result in a generated method with the following:
/// <summary>User is not in role '{0}'.</summary>
internal static string @UserNotInRole => GetResourceString("UserNotInRole");
/// <summary>User is not in role '{0}'.</summary>
internal static string FormatUserNotInRole(object p0)
=> string.Format(Culture, GetResourceString("UserNotInRole"), p0);
/// <summary>User is not in role '{0}'.</summary>
internal static string @UserNotInRole => GetResourceString("UserNotInRole");
/// <summary>User is not in role '{0}'.</summary>
internal static string FormatUserNotInRole(object p0)
=> string.Format(Culture, GetResourceString("UserNotInRole"), p0);
And allows to call it like a method with a parameter:
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a user is not in the specified <paramref name="role"/>.
/// </summary>
/// <param name="role">The duplicate role.</param>
/// <returns>An <see cref="IdentityError"/> indicating a user is not in the specified <paramref name="role"/>.</returns>
public virtual IdentityError UserNotInRole(string role)
{
return new IdentityError
{
Code = nameof(UserNotInRole),
Description = Resources.FormatUserNotInRole(role)
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a user is not in the specified <paramref name="role"/>.
/// </summary>
/// <param name="role">The duplicate role.</param>
/// <returns>An <see cref="IdentityError"/> indicating a user is not in the specified <paramref name="role"/>.</returns>
public virtual IdentityError UserNotInRole(string role)
{
return new IdentityError
{
Code = nameof(UserNotInRole),
Description = Resources.FormatUserNotInRole(role)
};
}
When i edit this file with more params like User is not in role '{0}' ABC: {1} the generated method will update properly to be generated like internal static string FormatUserNotInRole(object p0, object p1) . So now i want to achieve this within my own project. But somehow i couldn´t manage the localization to generate those damn parameters and i have absolutely no clue why. I´ve already set the generator as well as the file.
1 Reply
Lenon
Lenon2mo ago
My .csproj looks like:
<ItemGroup>
<EmbeddedResource Update="Resources\ErrorResources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>ErrorResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\ErrorResources.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>ErrorResources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
But the generated code is just
/// <summary>
/// Looks up a localized string similar to Failed to update the database {0}.
/// </summary>
internal static string DatabaseUpdateFailure {
get {
return ResourceManager.GetString("DatabaseUpdateFailure", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Failed to update the database {0}.
/// </summary>
internal static string DatabaseUpdateFailure {
get {
return ResourceManager.GetString("DatabaseUpdateFailure", resourceCulture);
}
}