介绍开源的.net通信框架NetworkComms框架之九 合并DLL

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了介绍开源的.net通信框架NetworkComms框架之九 合并DLL相关的知识,希望对你有一定的参考价值。

原文网址: http://www.cnblogs.com/csdev

Networkcomms 是一款C# 语言编写的TCP/UDP通信框架  作者是英国人  以前是收费的 目前作者已经开源  许可是:Apache License v2

开源地址是:https://github.com/MarcFletcher/NetworkComms.Net

 

合并Dll 不属于网络通信部分的功能,NetworkComms 框架带有这样一个Demo,用于合并所有的DLL.很有用,所以单独讲一下。

程序实际调用的是微软的ILMerge程序进行工作

技术分享

MergedDllBuild程序需要引用所有要合并的DLL所属的工程文件。

没有工程文件的,需要把Dll复制到 Bin目录下 

示例代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ILMerging;
using System.IO;
using System.Reflection;

namespace MergedDllBuild
{
    class Program
    {
        static void Main(string[] args)
        {
#if !DEBUG
            Version networkCommsVersion =
                new Version(Assembly.ReflectionOnlyLoad("NetworkCommsDotNet").FullName.
                    Split(,).
                    Where(s => s.Split(=).Length == 2).
                    ToDictionary(s => s.Split(=)[0].Trim(), s => s.Split(=)[1].Trim())["Version"]);

            string targetPlatform = "v2";
            string msCoreLibDirectory = @"C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727";

            bool coreBuildEnabled = false;
            bool completeBuildEnabled = true;

            #region Merge Core
            if (coreBuildEnabled)
            {
                Directory.CreateDirectory("MergedCore");
                File.Delete(@"MergedCore\\MergeLog.txt");
                ILMerge coreMerge = new ILMerge();

                List<string> coreAssembles = new List<string>();
                coreAssembles.Add("NetworkCommsDotNet.dll");
                coreAssembles.Add("protobuf-net.dll");
                coreAssembles.Add("ProtobufSerializer.dll");

                coreMerge.SetInputAssemblies(coreAssembles.ToArray());
                coreMerge.Version = networkCommsVersion;

                coreMerge.TargetKind = ILMerge.Kind.Dll;
                coreMerge.SetTargetPlatform(targetPlatform, msCoreLibDirectory);
                coreMerge.XmlDocumentation = true;

                coreMerge.KeyFile = "networkcomms.net.snk";

                coreMerge.OutputFile = @"MergedCore\\NetworkCommsDotNetCore.dll";

                coreMerge.Log = true;
                coreMerge.LogFile = @"MergedCore\\MergeLog.txt";

                coreMerge.Merge();
            }
            #endregion

            #region Merge Complete
            if (completeBuildEnabled)
            {
                Directory.CreateDirectory("MergedComplete");
                File.Delete(@"MergedComplete\\MergeLog.txt");
                ILMerge completeMerge = new ILMerge();

                List<string> completeAssembles = new List<string>();
                completeAssembles.Add("NetworkCommsDotNet.dll");
                completeAssembles.Add("protobuf-net.dll");
                completeAssembles.Add("ProtobufSerializer.dll");
                completeAssembles.Add("ICSharpCode.SharpZipLib.dll");
                completeAssembles.Add("SharpZipLibCompressor.dll");
                //completeAssembles.Add("QuickLZCompressor.dll");

                completeMerge.SetInputAssemblies(completeAssembles.ToArray());
                completeMerge.Version = networkCommsVersion;

                completeMerge.TargetKind = ILMerge.Kind.Dll;
                completeMerge.SetTargetPlatform(targetPlatform, msCoreLibDirectory);
                completeMerge.XmlDocumentation = true;

                completeMerge.KeyFile = "networkcomms.net.snk";

                completeMerge.OutputFile = @"MergedComplete\\NetworkCommsDotNetComplete.dll";

                completeMerge.Log = true;
                completeMerge.LogFile = @"MergedComplete\\MergeLog.txt";

                completeMerge.Merge();
            }
            #endregion
#endif
        }
    }
}
源码:http://pan.baidu.com/s/1dEJEdNz

以上是关于介绍开源的.net通信框架NetworkComms框架之九 合并DLL的主要内容,如果未能解决你的问题,请参考以下文章

介绍开源的.net通信框架NetworkComms框架 源码分析ConnectionState

介绍开源的.net通信框架NetworkComms框架之六 x509证书通信

介绍开源的.net通信框架NetworkComms框架之九 合并DLL

介绍开源的.net通信框架NetworkComms框架 源码分析ConnectionInfo

介绍开源的.net通信框架NetworkComms框架 源码分析(二十 )ConnectionCreate

介绍开源的.net通信框架NetworkComms框架 源码分析(二十三 )TCPConnection