适用于.NET Framework 4.5
ILMerge.exe /target:winexe /targetplatform:"v4,C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0" /out:finish.exe insert1.exe insert2.dll
cd C:\test
/out:finish.exe
将 finish.exe
替换成你想要的任何文件名。/out:finish.exe
后面,你必须给出要合并的文件。使用Costura.Fody。
您只需要安装NuGet,然后进行构建。最终的可执行文件将是独立的。
Install-Package Costura.Fody
,然后就大功告成了!你的构建将生成一个庞大的exe文件。 - Cristian Diaconescu将DLL文件作为资源引用,并使用AssemblyResolve事件返回资源DLL。
public partial class App : Application
{
public App()
{
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
Assembly thisAssembly = Assembly.GetExecutingAssembly();
//Get the Name of the AssemblyFile
var name = args.Name.Substring(0, args.Name.IndexOf(',')) + ".dll";
//Load form Embedded Resources - This Function is not called if the Assembly is in the Application Folder
var resources = thisAssembly.GetManifestResourceNames().Where(s => s.EndsWith(name));
if (resources.Count() > 0)
{
var resourceName = resources.First();
using (Stream stream = thisAssembly.GetManifestResourceStream(resourceName))
{
if (stream == null) return null;
var block = new byte[stream.Length];
stream.Read(block, 0, block.Length);
return Assembly.Load(block);
}
}
return null;
};
}
}
/target:winexe /target platform:"v4,C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"
:) - Yuki Kutsuyailmerge /target:winexe my_exe.exe my_dll.dll /out:merged.exe
- Momroilmerge /target:winexe /target:platform:"v4,c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\" /out:merged.exe my_exe.exe my_dll.dll
,但提示说我必须至少指定一个输入文件和一个输出文件。我也尝试将输出参数与输入参数交换,但没有结果。 - MomroInstall ILMerge as the other threads tell you to
Then go to the installation folder, by default
C:\Program Files (x86)\Microsoft\ILMerge
Drag your Dll's and Exes to that folder
Shift-Rightclick in that folder and choose open command prompt
Write
ilmerge myExe.exe Dll1.dll /out:merged.exe
Note that you should write your exe first.
这里有你合并后的exe文件。如果你只需要一次合并,那么这可能不是最好的方法,但是对于一次性使用来说,这是最简单的方法。我建议将Ildmerge添加到你的环境变量中。
ilmerge
添加到了我的系统路径中。
但仍未合并。请帮忙解决。在命令提示符中:
> ilmerge myExe.exe mfc100u.dll mfc110u.dll /out: final.exe
错误:“合并过程中出现异常:
ILMerge.Merge:无法从位置'C:\ test \ my folder \ mfc找到装配。 100u.dll'。跳过并处理其余参数。”有任何想法出了什么问题吗? - AB Bolimmfc100u.dll
有空格。我想合并多个 dll
文件。我也尝试过 ILMerge GUI
。但仍然面临同样的问题。请帮帮我。 - AB Bolimstatic class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
/* PUT THIS LINE IN YOUR CLASS PROGRAM MAIN() */
AppDomain.CurrentDomain.AssemblyResolve += (sender, arg) => { if (arg.Name.StartsWith("YOURDLL")) return Assembly.Load(Properties.Resources.YOURDLL); return null; };
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
首先将DLL文件添加到您的项目资源中。添加一个名为“Resources”的文件夹。
2019年更新(仅供参考):
从.NET Core 3.0开始,这个功能是支持的 开箱即用的。要利用单文件可执行文件发布功能,只需将以下行添加到项目配置文件中:
<PropertyGroup>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
现在,dotnet publish
应该能够生成单个 .exe 文件而无需使用任何外部工具。
有关此功能的更多文档,请参见https://github.com/dotnet/designs/blob/master/accepted/single-file/design.md。
RuntimeIdentifier
或 RuntimeIdentifiers
,文件就会减少约 65.4 MB。 - Daniel这里是官方文档。在步骤2中也会自动下载。
以下是一种非常简单的方法,我已经成功地使用.NET框架4.6.1
构建了我的应用程序。
Install ILMerge nuget package either via gui or commandline:
Install-Package ilmerge
Verify you have downloaded it. Now Install (not sure the command for this, but just go to your nuget packages):
Note: You probably only need to install it for one of your solutions if you have multiple
Navigate to your solution folder and in the packages folder you should see 'ILMerge' with an executable:
\FindMyiPhone-master\FindMyiPhone-master\packages\ILMerge.2.14.1208\tools
Now here is the executable which you could copy over to your \bin\Debug
(or whereever your app is built) and then in commandline/powershell do something like below:
ILMerge.exe myExecutable.exe myDll1.dll myDll2.dll myDlln.dll myNEWExecutable.exe
ILMerge.exe /target:winexe /targetplatform:"v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0" /out:finish.exe myExe.exe mfc100u.dll mfc110u.dll msvcp110.dll
出现错误:An exception occurred during merging: ILMerge.Merge: Could not load assembly from the location 'C:\test\my folder\mfc 100u.dll'. Skipping and processing rest of arguments.
有任何想法出了问题吗? - AB BolimProgram Files(x86)
2)输入ILMerge的完整路径。对于控制台应用程序,请使用/target:exe
。 - SWdVC:\Windows\Microsoft.NET\Framework
。因此,您也可以使用/targetplatform:"v2,C:\Windows\Microsoft.NET\Framework\v2.0.50727"
或/targetplatform:"v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319"
。 - Gray Programmerz