1. Create a Class Library:
namespace a{ public class Class1 { public string call() { return "Hello world!"; } }}
Generate a. dll backup for release.
2. Create WPF Application B:
Add a. dll reference, copy a. dll to Project B, and change it to an embedded resource,
Modify App. xaml and delete StartupUri = "MainWindow. xaml ",
Modify App. xaml. cs and rewrite OnStartup:
Using System. Reflection;
Namespace B {// <summary> // App. interaction logic of xaml // </summary> public partial class App: Application {protected override void OnStartup (StartupEventArgs e) {base. onStartup (e); AppDomain. currentDomain. assemblyResolve + = (sender, args) => {String projectName = Assembly. getExecutingAssembly (). getName (). name. toString (); using (var stream = Assembly. getExecutingAssembly (). getManifestResourceStream (projectName + ". a. dll ") {Byte [] B = new Byte [stream. length]; stream. read (B, 0, B. length); return Assembly. load (B) ;}}; MainWindow m = new MainWindow (); m. show ();}}}
Modify MainWindow. xaml. cs:
Namespace B {// <summary> // MainWindow. interaction logic of xaml // </summary> public partial class MainWindow: Window {public MainWindow () {InitializeComponent ();. class1 o = new. class1 (); MessageBox. show (o. call ());}}}
Generate, copy B .exe to the desktop (make sure there is no visible a. dll), and run it.