开发者

Plugin compiler structure?

Im making a modular program, and it supports dynamic compilation of source files in the plugin directory.

What I woul开发者_运维问答d like to do, to speed up loading times, is save compiled assemblies to a separate folder. When my program loads, and comes across a source file to compile, i would like it to check if there is an already compiled assembly, and use it IF the source file has not been changed since then. If the source file is changed, then re-compile and override the saved assembly.

My question to you is, what would be an effective way, to track which source file belongs to which assembly, and an effective way to track whether a source file has been changed since last load or not.


Change Tracking: Keep MD5 / CRC Hashes of the source files on record & Last Modified date, correlate the two to determine if the files have changed.

As for source->assembly, I suggest convention over configuration.


Why would you want to do that exactly? Anyone who is going to be using C# to write a plugin for you is going to know how to use Visual Studio and build a DLL. You'd be much better off defining a DLL interface for plugins to use instead. Then you wouldn't have to worry about loading times of any sort.

If the "plugin" is supposed to be changed from inside your program itself, you should probably just compile when the plugin is changed in your program rather than attempting to see when things get changed.


The only way (that I can think of) to guarantee this 100% is to keep a copy of the original source file along with the compiled version. Then you can do a file comparison between the original and the new one to see if they've changed, and if so, perform your compilation.


My question to you is, what would be an effective way, to track which source file belongs to which assembly, and an effective way to track whether a source file has been changed since last load or not

One way could be to:

  1. Use FileSystemWatcher to track file changes
  2. Keep an list(or table) to maintain source-assembly file associations.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜