C#4.0合并的.dll组件与.NET [英] C# 4.0 Merge .dll assembly with .NET

查看:136
本文介绍了C#4.0合并的.dll组件与.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定离开我的<一个href="http://stackoverflow.com/questions/4635573/merging-dll-files-with-ilmerge-failing-to-work">other问题不行了,因为我用杰弗里里希特的方法写在<一个想到的新思路href="http://blogs.msdn.com/b/microsoft_$p$pss/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx"相对=nofollow>这个页面合并一个.dll库,我的应用程序。所以,我说我的.dll文件作为嵌入资源,也增加一条,作为一个参考。然后,在Program.cs中(我不知道那里的code,他发布应该去),我说这样的:

I decided to leave my other question to die, since I thought of a new idea using Jeffrey Richter's method written on this page to merge a .dll library to my application. So I added my .dll file as an embedded resource and also added it as a reference. Then in Program.cs (I have no idea where the code he posted is supposed to go), I added this:

    ...
    [STAThread]
    static void Main()
    {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            string[] args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
                _in = args[1];
            SingleInstanceController controller = new SingleInstanceController();
            controller.Run(args);

            AppDomain.CurrentDomain.AssemblyResolve += (sender, argsx) =>
{
String resourceName = "AssemblyLoadingAndReflection." +
   new AssemblyName(argsx.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);
    }
}
        ;

我应该资源名称更改为其他内容?我有没有正确的方式加入它(在正确的地方)?

Am I supposed to change resourceName to something else? Have I added it correctly (in the right place)?

现在的问题是,它仍然没有找到和加载程序集,我不知道我做错了。任何帮助将是AP preciated。

Now the problem is, it still fails to find and load the assembly and I'm not sure what I've done wrong. Any help would be appreciated.

推荐答案

钩到AssemblyResolve事件之前的AppDomain尝试解析引用,即在入口点和第一道防线。

Hook to the AssemblyResolve event before the AppDomain tries to resolve references i.e in the entry point and the first line.

嵌入的资源名称开头的应用程序名称后面的资源名称。 例:ConsoleApplication.Test.dll

The embedded resource name starts with the application name followed by the resource name. ex: ConsoleApplication.Test.dll.

这篇关于C#4.0合并的.dll组件与.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆