// resx2res: 把 .resx(XML) 编译成 .resources(二进制),等价 SDK 的 resgen。 // 背景:本机无 Windows SDK 无 resgen.exe;csc 的 /resource 只会原样嵌入文件, // 直接嵌 resx 运行时报"流不是有效的资源文件"。msbuild(SD F5)会自动转换, // 命令行 csc 编译前需先用本工具生成 .resources。 // 用法: resx2res <输入.resx> <输出.resources> using System; using System.Collections; using System.Resources; class Resx2Res { static int Main(string[] args) { if (args.Length < 2) { Console.WriteLine("用法: resx2res "); return 1; } using (var reader = new ResXResourceReader(args[0])) { reader.UseResXDataNodes = true; using (var writer = new ResourceWriter(args[1])) { foreach (DictionaryEntry e in reader) { var node = e.Value as ResXDataNode; object val = node != null ? node.GetValue((System.ComponentModel.Design.ITypeResolutionService)null) : e.Value; writer.AddResource((string)e.Key, val); } } } Console.WriteLine("OK: " + args[1]); return 0; } }