Scott Hanselman

Exporting Resources from a Resource-Only Assembly

November 01, 2005 Comment on this post [0] Posted in Learning .NET
Sponsored By

I needed to compare two resource-only satellite assemblies to see what strings had changed. Sometimes we need to update a string here and there and QA needs to know exactly what changed. Here's a quick "ResourceExporter." It will export stuff in a name=value format, which can, by the way, be turned back into RESX files using resgen.exe. No warrenty express or implied. I've run it successfully on the two assemblies I was comparing. Your Mileage May Vary.

    1 static void Main(string[] args)
    2 {
    3     Assembly a = Assembly.LoadFile(Path.Combine(System.Environment.CurrentDirectory,args[0]));
    4     string[] resources = a.GetManifestResourceNames();
    5     using (StreamWriter strWriter = File.CreateText(
    6     {
    7         foreach(string resourceName in resources)
    8         {
    9             using(Stream str = a.GetManifestResourceStream(resourceName))
   10             {
   11                 using(ResourceReader reader = new ResourceReader(str))
   12                 {
   13                     foreach(DictionaryEntry entry in reader)
   14                     {
   15                         strWriter.WriteLine(String.Format("{0}={1}", entry.Key, entry.Value));
   16                     }
   17                 }
   18             }
   19         }
   20     }
   21 }

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.