[英]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.