原文网址: 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
时间: 2024-10-12 07:19:39