以编程方式为resx文件生成Designer.cs(ResXResourceWriter/ResXResourceReader) [英] Programmatically generate Designer.cs for resx file (ResXResourceWriter/ResXResourceReader)
本文介绍了以编程方式为resx文件生成Designer.cs(ResXResourceWriter/ResXResourceReader)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用ResXResourceWriter/ResXResourceReader在TFS中创建/更新resx文件,但不会生成.Designer.cs文件.我看到Resgen创建了.Designer.cs.如何在特定的TFS文件路径下以编程方式调用该文件以生成.Designer.cs?是这样吗
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);
推荐答案
我发现了如何以编程方式生成.Designer.cs文件.
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;
这篇关于以编程方式为resx文件生成Designer.cs(ResXResourceWriter/ResXResourceReader)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文