简体   繁体   中英

Including .dll files in C# Forms Application

I am using Visual Studio 2019 to build a C# Forms application. When publishing an .exe file from a Console application, I have the option to include all the .dll files into the .exe, meaning that users of my application only need to download one file. However, when publishing an .exe from a Forms application, I'm forced to include all of these .dll files independently:

View of folder with .dll files

Is there a way to include these .dll files inside of the .exe so that I only have to send someone the .exe file for them to be able to run it, similar to how it's possible for Console applications?

EDIT: I've discovered that I was in .NET Core and should've been in .NET Framework. I'm relatively new to C# and wasn't aware of the differences. This issue is now resolved! If anyone runs into this problem, just copy-paste your code over to .NET Framework and listen to the instructions in the description.

You need to change the configuration settings during the build step to be "self-contained":

Using dotnet cli

dotnet publish -r win-x64 -c Release --self-contained

Using Visual Studio

  1. Add <PublishSingleFile>true</PublishSingleFile> to your project file.

  2. On the Solution Explorer pane, right-click on the project you want to publish. Select Publish .

    解决方案浏览器

    If you don't already have a publishing profile, follow the instructions to create one and choose the Folder target-type.

  3. Choose Edit .

    编辑

  4. In the Profile settings dialog, set the following options:

    • Set Deployment mode to Self-contained or Framework-dependent .
    • Set Target runtime to the platform you want to publish to. (Must be something other than Portable .)
    • Select Produce single file .

    Choose Save to save the settings and return to the Publish dialog.

    配置文件设置

  5. Choose Publish to publish your app as a single file.

For more information, see Visual Studio Docs: Single file deployment and executable .


Duplicate of Embedding DLLs in a compiled executable

I don't think compile all files into one is a good idea. If you want to have single file for downloading, you can package them into a self-extract zip format (winRAR, winzip or 7zip). Good luck~~

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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