简体   繁体   English

如何在Winforms中创建仅具有exe且无依赖关系的安装程序?

[英]How do I create an installer with only exe and no dependencies in Winforms?

I have seen applications that once installed only have a .exe file in the folder and no dependencies that is (no dll , no xml , no ico ) nothing. 我见过的应用程序一旦安装只在文件夹中有一个.exe文件,没有任何依赖(没有dll ,没有xml ,没有ico )。 I have seen one in a Point of Sale application. 我在销售点应用程序中看到过一个。

How do I do this using Visual Studio , Winforms and C# ? 我如何使用Visual StudioWinformsC#执行此操作?

To merge dependencies (DLLs and assemblies) you can use Microsoft ILMerge . 要合并依赖项(DLL和程序集),可以使用Microsoft ILMerge ILMerge is a utility that merges multiple .NET assemblies into a single assembly. ILMerge是一个将多个.NET程序集合并到一个程序集中的实用程序。

ILMerge takes a set of input assemblies and merges them into one target assembly. ILMerge接受一组输入程序集并将它们合并到一个目标程序集中。 The first assembly in the list of input assemblies is the primary assembly. 输入程序集列表中的第一个程序集是主程序集。 When the primary assembly is an executable, then the target assembly is created as an executable with the same entry point as the primary assembly. 当主程序集是可执行文件时,目标程序集将创建为具有与主程序集相同的入口点的可执行文件。 Also, if the primary assembly has a strong name, and a .snk file is provided, then the target assembly is re-signed with the specified key so that it also has a strong name. 此外,如果主程序集具有强名称,并且提供了.snk文件,则使用指定的键重新签名目标程序集,以使其具有强名称。

Example: 例:

    @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%

If it's hard for you to use ILMerge in command-line or in your build process I suggest ILMerge-Gui tool . 如果您很难在命令行或构建过程中使用ILMerge,我建议使用ILMerge-Gui工具 It gives you short and simple UI to merge your dependencies as a single exe file. 它为您提供简短的UI,将您的依赖项合并为单个exe文件。

IL合并

Please don't forget to read the ILMerge website. 请不要忘记阅读ILMerge网站。

You could use Fody-Costura . 你可以使用Fody-Costura It comes as a NuGet package and merges dependecies so that you have one .exe at the end. 它作为一个NuGet包并合并依赖,以便最后有一个.exe。 Worked perfectly for me. 为我工作完美。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM