2

In Visual Studio 2010 under .NET4, is there a good way to instance, populate, and binary-serialize classes as part of the build process? I am writing an application which takes several seconds to load a complex set of interrelated classes to the same "startup state" each time, and I suspect if I could load them from a serialized image, load times would virtually disappear.

My question is not about XNA, but I recently spent some time playing around with Xbox programming under the XNA Framework. The Framework adds an interesting pre-processing feature (the Content Pipeline) which does exactly what I have described: important classes from the main application can be instanced and populated (using a different block of code which is only used during build-time pre-processing), then serialized to a deployment file. This serialized version is reloaded at runtime to significantly improve initialization performance. (Under XNA this process also allows target-platform tweaks like byte-order changes which don't matter for my question.)

I realize I'd have to manually kick off deserialization, I know it wouldn't be automated to that extent -- my concern is on the build side.

Does anything like this exist for VS2010 outside the XNA Framework? This is not T4-style codegen (which still requires runtime processing, although it would probably perform better than reading an external file), and I'm not sure whether I could just write a separate project to create and dump those classes to disk then safely reload them later in a different project (some experimentation is probably called for), but even if that works, it still lacks integration with the build process. I can't just hijack the XNA Framework plugin as it has many XNA-specific ties and the load-side process is XNA only.

Note that I'm willing to consider reasonably-priced third-party plugins (I wouldn't balk at $30 or $40 for this, but I'm not buying a tool that costs hundreds of dollars).

McGuireV10
  • 9,572
  • 5
  • 48
  • 64
  • I'm not aware of any package that does this, but if I were to develop my own solution I'd start with MSBuild to manage the process. Consequently, that might be an alternative research angle you want to take, and a tag to apply to this question. – Snixtor May 21 '12 at 23:06
  • Good point, thanks. And I removed "resource files" since I don't really want to do that. I've done some testing and a file that takes 3.3 seconds to load through parsing will load through deserialization in about 220 milliseconds. Right now I've just written some #define calls to control when they're called, but of course, tying it to the build would mean I can just change the "source" and it would build automatically as-needed. – McGuireV10 May 22 '12 at 11:21
  • Doing anything at build time is only relevant for XML serialization, binary serialization doesn't require nor use that kind of help. You shouldn't have a problem profiling the problem if it takes 3 seconds. – Hans Passant May 22 '12 at 13:01
  • I think you may have misunderstood what I am trying to accomplish. Build time: (1) compile data classes, (2) compile parser, (3) parse data and serialize the data classes. At runtime, I'll do this: (1) deserialize the data. How I serialize it is not relevant. What I want is to automate the parsing and serialization as part of the build process without deploying that class as part of the final build. It would also be nice if the build system recognized source data and data class dependencies so that the parsing and serialization only happens when there are relevant changes. – McGuireV10 May 22 '12 at 16:24

0 Answers0