Stan
Stan

Reputation: 746

MSBuild from In-Memory Resources

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?

Upvotes: 2

Views: 691

Answers (2)

Hans Passant
Hans Passant

Reputation: 942255

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 a future version of C#, plans are to provide 'compiler as a service' feature. Current internal project name is Roslyn. Whether that will affect the build process is murky, I doubt it but have no real clue how it will be integrated with the existing compiler, if at all.

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 for most any C# project, 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.

Upvotes: 5

Giorgi
Giorgi

Reputation: 30883

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

Upvotes: 2

Related Questions