views:

259

answers:

1

I am generating a WPF UserControl in code that I would like to save as a DLL for use in a different application. The process of saving the DLL needs to be fully automated. Would it be better to try to do this with System.Reflection or by shelling out to csc? Or, is there an even better way to do this?

John

A: 

I think you should use CodeCompiler for that purpose. There is no need in Reflection or shelling out csc as all the required support is already provided within .net framework.

Check out the Microsoft Support article: "How to programmatically compile code using C# compiler". Also take a look at the "System.CodeDom.Compiler" namespace at MSDN.

Also you will need to perform some googling in order to find samples that suite your needs. Code generation had been discussed a lot so you won't have problems finding samples.

You might be also interested in automating of your source code generation so T4 is also worth looking at. Refer to Oleg Sych blog to find out all details towards T4 generation.

Denis Vuyka