tags:

views:

39

answers:

2

Is it possible for MSBuild to build an EXE from purely in-memory resources. For example, let's say I built a .csproj and a couple of forms and code-behind and saved to a memory stream, could MSBuild use these streams to build out an EXE?

The purpose is that nothing is written to disk except the final EXE.

If so, is there a good blog post or other reference about this subject?

+1  A: 

Why not use CodeDomProvider.CompileAssemblyFromSource Method to compile the code you hold in memory?

Giorgi
It actually uses a file.
Hans Passant
Would `CodeDomProvider.CompileAssemblyFromDom` be a better way of achieving "not writing to disk"? What I mean is *I don't want to write anything to disk (except the final output), regardless of what CodeDom does on it's own, like use the disk.*
WinnerWinnerChickenDinner
+2  A: 

MSBuild doesn't create an EXE file, a compiler does. None of the Microsoft compilers currently support compiling from a memory stream. System.CodeDom provides an illusion of it but it actually uses the disk.

There's stuff coming in the next version of C#, plans are to provide 'compiler as a service' feature. Whether that will affect the build process is murky, I doubt it but have no real clue what it will look like. One of the key properties of Windows is that there is only a slight difference between memory and files. Anything in memory is also in a file, the paging file for example. Memory is only a fast way to read and write file data. When you read or write a file, you are actually reading/writing memory. The file system cache. If it is big enough, it is, the compiler will read that same memory without ever hitting the disk. It will only slow down when the file hasn't been read or written recently.

Hans Passant
I guess I don't have a good understanding for what MSBuild is for then. To compile an app, is just System.CodeDom enough, assuming all of those files are in order? Can these files, including resources such as images, all be in memory like from a institated class that builds all the needed files (regardless of what CodeDom does on it's own like using the disk)?
WinnerWinnerChickenDinner
MSBuild is there to run the right compiler at the right time. Not just csc.exe, but sgen.exe, resgen.exe, etc. No, System.CodeDom isn't nearly enough to do the equivalent job. The point I tried to make was that using memory isn't nearly as sexy as it may sound. I'd recommend Windows Internals to get a good insight.
Hans Passant