Yuk*_*uya 86
对于.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
Run Code Online (Sandbox Code Playgroud)
cd C:\test/out:finish.exe替换finish.exe为您想要的任何文件名./out:finish.exe你必须提供你想要组合的文件后面.Igo*_*pov 22
使用Costura.Fody.
你只需要安装nuget然后进行构建.最终的可执行文件将是独立的.
Des*_*tor 16
将DLL引用到您的Resources,并使用AssemblyResolve-Event返回Resource-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;
};
}
}
Run Code Online (Sandbox Code Playgroud)
The*_*ker 10
下载
呼叫
ilmerge /target:winexe /out:c:\output.exe c:\input.exe C:\input.dll
Run Code Online (Sandbox Code Playgroud)
按其他线程告诉您安装ILMerge
然后转到安装文件夹,默认情况下
C:\Program Files (x86)\Microsoft\ILMerge
将Dll和Exes拖到该文件夹中
按住Shift键并右键单击该文件夹,然后选择打开命令提示符
写
ilmerge myExe.exe Dll1.dll /out:merged.exe
Run Code Online (Sandbox Code Playgroud)
请注意,您应该首先编写您的exe.
你有合并的exe.如果你多次这样做,这可能不是最好的方法,但最简单的一次使用,我建议把Ilmerge放到你的路上.
小智 6
static 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());
}
}
Run Code Online (Sandbox Code Playgroud)
首先将DLL添加到项目资源中.添加文件夹"资源"
2019年更新(仅供参考):
从.NET Core 3.0开始,开箱即用地支持此功能。要利用单文件可执行文件发布,只需将以下行添加到项目配置文件中:
<PropertyGroup>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
现在,dotnet publish应该在不使用任何外部工具的情况下生成单个 .exe 文件。
有关此功能的更多文档,请访问https://github.com/dotnet/designs/blob/master/accepted/single-file/design.md。
| 归档时间: |
|
| 查看次数: |
90254 次 |
| 最近记录: |