简体   繁体   English

WPF 用户控制到 DLL 以编程方式

[英]WPF UserControl to DLL Programmatically

I am generating a WPF UserControl in code that I would like to save as a DLL for use in a different application.我正在代码中生成 WPF UserControl,我想将其保存为 DLL 以用于不同的应用程序。 The process of saving the DLL needs to be fully automated.保存 DLL 的过程需要完全自动化。 Would it be better to try to do this with System.Reflection or by shelling out to csc?尝试使用 System.Reflection 或使用 csc 来执行此操作会更好吗? Or, is there an even better way to do this?或者,有没有更好的方法来做到这一点?

I think you should use CodeCompiler for that purpose.我认为您应该为此目的使用 CodeCompiler。 There is no need in Reflection or shelling out csc as all the required support is already provided within .net framework.由于 .net 框架中已经提供了所有必需的支持,因此不需要反射或脱壳 csc。

Check out the Microsoft Support article: "How to programmatically compile code using C# compiler" .查看 Microsoft 支持文章: “如何使用 C# 编译器以编程方式编译代码” Also take a look at the " System.CodeDom.Compiler " namespace at MSDN.还可以查看 MSDN 上的“ System.CodeDom.Compiler ”命名空间。

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.您可能还对自动生成源代码感兴趣,因此 T4 也值得一看。 Refer to Oleg Sych blog to find out all details towards T4 generation.请参阅Oleg Sych博客以了解有关 T4 生成的所有详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM