[英]How do I create an installer with only exe and no dependencies in Winforms?
我见过的应用程序一旦安装只在文件夹中有一个.exe
文件,没有任何依赖(没有dll
,没有xml
,没有ico
)。 我在销售点应用程序中看到过一个。
我如何使用Visual Studio
, Winforms
和C#
执行此操作?
要合并依赖项(DLL和程序集),可以使用Microsoft ILMerge 。 ILMerge是一个将多个.NET程序集合并到一个程序集中的实用程序。
ILMerge接受一组输入程序集并将它们合并到一个目标程序集中。 输入程序集列表中的第一个程序集是主程序集。 当主程序集是可执行文件时,目标程序集将创建为具有与主程序集相同的入口点的可执行文件。 此外,如果主程序集具有强名称,并且提供了.snk文件,则使用指定的键重新签名目标程序集,以使其具有强名称。
例:
@echo off
:: this script needs https://www.nuget.org/packages/ilmerge
:: set your target executable name (typically [projectname].exe)
SET APP_NAME=myapp.exe
:: Set build, used for directory. Typically Release or Debug
SET ILMERGE_BUILD=Debug
:: Set platform, typically x64
SET ILMERGE_PLATFORM=x64
:: set your NuGet ILMerge Version, this is the number from the package manager install, for example:
:: PM> Install-Package ilmerge -Version 3.0.21
:: to confirm it is installed for a given project, see the packages.config file
SET ILMERGE_VERSION=3.0.21
:: the full ILMerge should be found here:
SET ILMERGE_PATH=%USERPROFILE%\.nuget\packages\ilmerge\%ILMERGE_VERSION%\tools\net452
:: dir "%ILMERGE_PATH%"\ILMerge.exe
echo Merging %APP_NAME% ...
:: add project DLL's starting with replacing the FirstLib with this project's DLL
"%ILMERGE_PATH%"\ILMerge.exe Bin\x64\Release\%APP_NAME% ^
/lib:Bin\%ILMERGE_PLATFORM%\%ILMERGE_BUILD%\ ^
/out:%APP_NAME% ^
FirstLib.dll ^
mylib1.dll ^
Microsoft.lib2.dll ^
SomeOtherLib.dll ^
\otherlibdir\otherlib.dll
:Done
dir %APP_NAME%
如果您很难在命令行或构建过程中使用ILMerge,我建议使用ILMerge-Gui工具 。 它为您提供简短的UI,将您的依赖项合并为单个exe文件。
请不要忘记阅读ILMerge网站。
你可以使用Fody-Costura 。 它作为一个NuGet包并合并依赖,以便最后有一个.exe。 为我工作完美。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.