.NET 5 未编译为单个文件可执行文件 [英] .NET 5 not compiling to single file executables

查看:31
本文介绍了.NET 5 未编译为单个文件可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨呀!我在通过 Visual Studio 调试时尝试将我的 .NET 5 应用程序编译为单个文件可执行文件时遇到问题.

Haiya! I'm having an issue regarding trying to compile my .NET 5 application to a single file executable while debugging through Visual Studio.

我的 CSProject 如下.

My CSProject is bellow.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net50</TargetFramework>
    <AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PublishSingleFile>true</PublishSingleFile>
    <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>

</Project>

我将我的运行时标识符设置为 winx64 并将发布单个文件设置为 true,但是在构建时我留下了一堆 DLL,我的应用程序使用这些 DLL(总共 272 个).我想知道 - 我如何将这些 DLL 打包到这个应用程序中?我原以为将它发布为单个文件可执行文件已经可以做到这一点-

I have my runtime identifier set to winx64 and publish single file set to true, yet when building I'm left with a bunch of DLLs that my application uses building along-side it (a total of 272 in total). I was wondering - how would I package these DLLs into this application? I had thought that publishing it as a single file executable would do that already-

推荐答案

对于 .Net 5,要在发布项目时获得单个可运行的可执行文件,重要的属性是:

For .Net 5, to get a single runnable executable file when you publish your project, the important properties are:

  • 发布单个文件
  • 自包含
  • IncludeAllContentForSelfExtract
  • 运行时标识符

您要么需要将它们自己包含在项目文件中,要么在命令行中指定它们.

You'll either need to include them in the project file themselves, or specify them on the command line.

项目文件:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <!--<OutputType>WinExe</OutputType>--><!--Use this for WPF or Windows Forms apps-->
        <TargetFramework>net5.0</TargetFramework>
        <!--<TargetFramework>net5.0-windows</TargetFramework>--><!--Use this for WPF or Windows Forms apps-->
        <PublishSingleFile>true</PublishSingleFile>
        <SelfContained>true</SelfContained>
        <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
        <RuntimeIdentifier>win-x64</RuntimeIdentifier><!--Specify the appropriate runtime here-->
    </PropertyGroup>

</Project>

命令行界面:

dotnet publish -r win-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true

根据您的需求,还有其他值得考虑的属性,例如:

There are other properties worth considering depending on what your needs are, for example:

  • 发布修剪
  • PublishReadyToRun

在此处查看文档页面:

https://docs.microsoft.com/en-us/dotnet/core/deploying/single-filehttps://github.com/dotnet/designs/blob/main/accepted/2020/single-file/design.md

这篇关于.NET 5 未编译为单个文件可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆