Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In which format is Target field in the EF Migration resx files?

With Entity Framework, while using Migration files with code-first, it generates .resx files (xml), which contains a data field named Target:

  <data name="Target" xml:space="preserve">
    <value>H4sIAAAAAAAEAO ... ICAA==</value>
  </data>

In which format is that field? The == at the end of the data make think it is base64, but when decoded, it looked like it is binary data. Anyone know the structure/format of the data?

like image 667
Matthieu Charbonnier Avatar asked Dec 12 '17 08:12

Matthieu Charbonnier


1 Answers

It is an edmx/xml file that has been gzipped and then base64 encoded. The following application will print out the xml for a given .resx file.

using System;
using System.Collections;
using System.IO;
using System.IO.Compression;
using System.Resources;
using System.Xml.Linq;

namespace ResxReader
{
    class Program
    {
        private const string ResxFilename = @"full path to your .resx file";

        public static void Main()
        {
            var reader = new ResXResourceReader(ResxFilename);
            IDictionaryEnumerator resources = reader.GetEnumerator();

            while (resources.MoveNext())
            {
                if ("Target".Equals(resources.Key))
                {
                    XDocument target = Decompress(Convert.FromBase64String(resources.Value.ToString()));

                    Console.Write(target);
                }
            }
        }

        public static XDocument Decompress(byte[] bytes)
        {

            using (var memoryStream = new MemoryStream(bytes))
            {
                using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
                {
                    return XDocument.Load(gzipStream);
                }
            }
        }
    }
}
like image 95
Phil W Avatar answered Sep 25 '22 19:09

Phil W