Static Linking of libraries created on C# .NET

后端 未结 5 1679
春和景丽
春和景丽 2020-12-01 02:26

I\'m using VS2008 C#.NET.

I created 3 different classes of libraries in 3 projects. I wrote an application which uses these libraries (dlls).

What is happeni

5条回答
  •  孤独总比滥情好
    2020-12-01 02:37

    Stumbled across this question, and found another method of achieving these ends from Jeffrey Richter (http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx): you can embed your .dll into your executable as a resource, then overload the AssemblyResolve event to load the assembly that way. Quoting the code from the link:

    AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
       String resourceName = "AssemblyLoadingAndReflection." +
          new AssemblyName(args.Name).Name + ".dll";
       using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) {
          Byte[] assemblyData = new Byte[stream.Length];
          stream.Read(assemblyData, 0, assemblyData.Length);
          return Assembly.Load(assemblyData);
       }
    };
    

提交回复
热议问题