Write a program that writes itself...

time to read 6 min | 1054 words

It turns out that you can do that quite easily with .Net:

static void Main(string[] args)

{

      Assembly executingAssembly = Assembly.GetExecutingAssembly();

      foreach (string manifestResourceName in executingAssembly.GetManifestResourceNames())

      {

            Console.WriteLine("File {0}:", manifestResourceName);

            if(Path.GetExtension(manifestResourceName)==".cs")

            {

                  Stream stream = executingAssembly.GetManifestResourceStream(manifestResourceName);

                  Console.Write(new StreamReader(stream).ReadToEnd());

            }

      }

}

This little magic is possible when you add this to the very buttom of your csproj:

<ItemGroup>

      <EmbeddedResource Include="@(Compile)" />

</ItemGroup>

Now I just need to figure out how to reference the currectly executing msbuild project and I would have the entire project in the binaries. Sadly, I understand that this is something that is required at times. (Usually deperatedly so :-) ).

I wonder if I can somehow make it a part of machine.msbuild, or something like that?

Give a new meaning to "ships with source code" :-)