From 5f5e49cbb4bb7bd539a27e07548128a72ebaacae Mon Sep 17 00:00:00 2001 From: iSazonov Date: Fri, 2 Jun 2017 16:52:49 +0300 Subject: [PATCH 1/2] Enhance ResGen tool to support a command line argument ResGen tool process all resx files in PowerShell Repo at a time. Now we can process resx files one at a time. It is useful for MSBuild. --- src/ResGen/Program.cs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/ResGen/Program.cs b/src/ResGen/Program.cs index 712a6543d76..5f75d9d310e 100644 --- a/src/ResGen/Program.cs +++ b/src/ResGen/Program.cs @@ -10,12 +10,30 @@ public class Program { public static void Main(string[] args) { - // we are assuming resgen is run with 'dotnet run' - // so we can use relative paths - foreach (string folder in Directory.EnumerateDirectories("..")) + IEnumerable dirs; + string fileFilter; + + if (args.Length == 1) + { + // We are assuming resgen is run with 'dotnet run pathToResxFile.resx'. + fileFilter = Path.GetFileName(args[0]); + string moduleDirectory = Directory.GetParent(Path.GetDirectoryName(args[0])).FullName; + dirs = new List() { moduleDirectory }; + } + else + { + // We are assuming resgen is run with 'dotnet run' + // so we can use relative path to get a parent directory + // to process all *.resx files in all project subdirectories. + fileFilter = "*.resx"; + dirs = Directory.EnumerateDirectories(".."); + } + + foreach (string folder in dirs) { string moduleName = Path.GetFileName(folder); string resourcePath = Path.Combine(folder, "resources"); + if (Directory.Exists(resourcePath)) { string genFolder = Path.Combine(folder, "gen"); @@ -24,7 +42,7 @@ public static void Main(string[] args) Directory.CreateDirectory(genFolder); } - foreach (string resxPath in Directory.EnumerateFiles(resourcePath, "*.resx")) + foreach (string resxPath in Directory.EnumerateFiles(resourcePath, fileFilter)) { string className = Path.GetFileNameWithoutExtension(resxPath); string sourceCode = GetStronglyTypeCsFileForResx(resxPath, moduleName, className); From eec961f351a788297cca515b5da8c078d6559bac Mon Sep 17 00:00:00 2001 From: Ilya Date: Sun, 25 Jun 2017 21:48:37 +0500 Subject: [PATCH 2/2] Use Path.GetDirectoryName --- src/ResGen/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ResGen/Program.cs b/src/ResGen/Program.cs index 5f75d9d310e..8bc235b14a0 100644 --- a/src/ResGen/Program.cs +++ b/src/ResGen/Program.cs @@ -17,7 +17,7 @@ public static void Main(string[] args) { // We are assuming resgen is run with 'dotnet run pathToResxFile.resx'. fileFilter = Path.GetFileName(args[0]); - string moduleDirectory = Directory.GetParent(Path.GetDirectoryName(args[0])).FullName; + string moduleDirectory = Path.GetDirectoryName(Path.GetDirectoryName(args[0])); dirs = new List() { moduleDirectory }; } else