Programmatically generate Designer.cs for resx file (ResXResourceWriter/ResXResourceReader)
Asked Answered
B

1

15

I'm creating/updating resx files in TFS using ResXResourceWriter/ResXResourceReader which doesnt generate the .Designer.cs file. I saw that Resgen creates the .Designer.cs. How can i call that programmatically to generate the .Designer.cs at a certain TFS file path? Is it something like this?

ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\Program Files\Microsoft.NET\SDK\v2.0 64bit\Bin\ResGen.exe");
                startInfo.WindowStyle = ProcessWindowStyle.Minimized;
                startInfo.Arguments = "ResourceName.resx /publicClass /str:cs, Namespace, ResourceName, ResourceName.Designer.cs";
                Process.Start(startInfo);
Brumley answered 16/9, 2010 at 17:42 Comment(0)
B
20

I found out how to programmatically generate the .Designer.cs file.

string[] unmatchedElements;
var codeProvider = new Microsoft.CSharp.CSharpCodeProvider();
System.CodeDom.CodeCompileUnit code =
    System.Resources.Tools.StronglyTypedResourceBuilder.Create(
        "MyClass.resx", "MyClass", "my.namespace", codeProvider, 
        true, out unmatchedElements); // Needs System.Design.dll

using(StreamWriter writer = new StreamWriter("MyClass.Designer.cs", false,
    System.Text.Encoding.UTF8))
{
    codeProvider.GenerateCodeFromCompileUnit(code, writer,
        new System.CodeDom.Compiler.CodeGeneratorOptions());
}

// Returns false if at least one ppty couldn't be generated.
return unmatchedElements.Length == 0; 
Brumley answered 21/9, 2010 at 20:16 Comment(1)
So, solved? I was just going to give you that MSDN link: msdn.microsoft.com/en-us/library/gg418542.aspx ;)Mangum

© 2022 - 2024 — McMap. All rights reserved.