Search code examples
c#resources.net-4.0embedded-resource

How to use an embedded .NET exe in a C# library without rebuilding the file from its byte[]?


I have an embedded file - xsd.exe - in my .NET library.

How can I, without rebuilding the embedded file from its byte[], use it?

The exe runs on the command line so I need to be able to make calls like: xsd /o:.. or whatever.

I have read something about ManifestResourceStream but I can't seem to find it in the framework and I have no idea how to use it.

Any ideas?


Solution

  • If you can write it to a temp file (File.WriteAllBytes), you can create a new AppDomain, and use yourAppDomain.ExecuteAssembly(...); however, to do this manually from a byte[], I expect you would need to load it manually with Assembly.Load(byte[],...), look at the loadedAssembly.EntryPoint, and use reflection to invoke it. The ExecuteAssembly approach is far easier...

    Of course, if you can write it to a file, you could also just use Process.Start which is even more easy ;p

    You might also want to double-check redist/deployment rights re xsd.exe.