I'm trying to generate .Designer.cs file for my .resx file with msbuild. I use these properties:
<ItemGroup>
<Compile Update="Resources\Resource.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resource.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\Resource.id.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Resource.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<StronglyTypedFileName>Resources\Resource.Designer.cs</StronglyTypedFileName>
<StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
<StronglyTypedNamespace>home_server.Client.Web.Resources</StronglyTypedNamespace>
<StronglyTypedClassName>Resource</StronglyTypedClassName>
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
Those settings generates the .Designer.cs file but it has wrong access modifier:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace home_server.Client.Web.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// This class was generated by MSBuild using the GenerateResource task.
/// To add or remove a member, edit your .resx file then rerun MSBuild.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Build.Tasks.StronglyTypedResourceBuilder", "15.1.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resource {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resource() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("home_server.Client.Web.Resources.Resource", typeof(Resource).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Cancel.
/// </summary>
internal static string cancel {
get {
return ResourceManager.GetString("cancel", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Error.
/// </summary>
internal static string error {
get {
return ResourceManager.GetString("error", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Go Home.
/// </summary>
internal static string go_home {
get {
return ResourceManager.GetString("go_home", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Loading.
/// </summary>
internal static string loading {
get {
return ResourceManager.GetString("loading", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No such thing.
/// </summary>
internal static string no_such_thing {
get {
return ResourceManager.GetString("no_such_thing", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to OK.
/// </summary>
internal static string ok {
get {
return ResourceManager.GetString("ok", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to tes.
/// </summary>
internal static string tes {
get {
return ResourceManager.GetString("tes", resourceCulture);
}
}
}
}
And this is the resx file content:

Generate .Designer.cs file with public modifier.
Generates the file with internal modifier instead.
Sorry if this has been discussed before as I cant find it anywhere else.
Thanks
Team Triage: We believe this is an issue with VS, not MSBuild. Can you open a feedback ticket instead?
huh? i use dotnet build command to generate that file.
even the file said:
/// To add or remove a member, edit your .resx file then rerun MSBuild.
please reopen the issue. i believe this has nothing to do with visual studio. thank you.
@realivanjx 馃憤 we'll take another look at this in the next bug triage. In the meantime, could you provide a minimal project that reproduces this, or steps on doing so?
here you go. the details are in readme.
To check in the repro: Does the publicresxfilecodegenerator file already exist? and if you delete them, does it get generated in the same way?
You mean the .Designer.cs file? I deleted it from the repro zip but if you run dotnet build it should be generated automatically, still with wrong modifiers of course.
Also please use the dotnet build command directly. If you build from visual studio it will be generated with resgen instead of msbuild.
Tested the repro. The .Designer.cs file is indeed generated by dotnet build with the internal modifier. When generating using the same repro in VS, the modifiers are public. I wonder if MSBuild supports the generator PublicResXFileCodeGenerator at all, that seems to be the VS feature (VS wrapper around StronglyTypedResourceBuilder Class).
However, it is possible to generate the file with public modifiers, one need to set PublicClass to true:
<ItemGroup>
<Compile Update="MyResource.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>MyResource.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="MyResource.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<PublicClass>true</PublicClass>
<StronglyTypedFileName>MyResource.Designer.cs</StronglyTypedFileName>
<StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
<StronglyTypedNamespace>test</StronglyTypedNamespace>
<StronglyTypedClassName>MyResource</StronglyTypedClassName>
<LastGenOutput>MyResource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
Thanks @AR-May for pointing out. It seems that PublicResXFileCodeGenerator is not supported by msbuild. I ended up with this in my csproj file:
<ItemGroup>
<Compile Update="Resources\Resource.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resource.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\Resource.id.resx">
<Generator>ResXFileCodeGenerator</Generator>
<PublicClass>true</PublicClass>
</EmbeddedResource>
<EmbeddedResource Update="Resources\Resource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<PublicClass>true</PublicClass>
<StronglyTypedFileName>Resources\Resource.Designer.cs</StronglyTypedFileName>
<StronglyTypedLanguage>CSharp</StronglyTypedLanguage>
<StronglyTypedNamespace>home_server.Client.Web.Resources</StronglyTypedNamespace>
<StronglyTypedClassName>Resource</StronglyTypedClassName>
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
Thanks. I will close this issue now.