c# - PublishSingleFile 不生成单个可执行文件
问题描述
我有一个 .Net Core 3 控制台应用程序,我正在尝试将其发布为自包含的单个可执行文件。我过去能够做到这一点,但令我惊讶的是它不再起作用。项目结构是一个带有两个程序集的控制台应用程序,都在 Core 3 中。
如果我使用dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true
我希望输出是几个 mb 大小的单个可执行文件。但是,发布文件夹包含可执行文件(几百 kb)和一个 .dll 文件以及 .cache 文件和 pdb。
我的控制台应用程序的配置如下:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
如果我直接从 Visual Studio 发布应用程序,我会得到与上面相同的结果。
所以我的问题归结为:为什么这个配置或发布语句不会产生一个自包含的单个可执行文件?
解决方案
I can get my 3.1 console app to publish with the following:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>..\..\Binaries\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<DebugType>None</DebugType>
</PropertyGroup>
</Project>
If I set PublishReadyToRun to True (or add PublishTrimmed as True) it fails. Adding DebugType None prevents it publishing the pdb file for the exe.
UPDATE: removing the SelfContained tag stops it creating the 'dotnetcoreapp3.1' folder.
推荐阅读
- python - python pandas read_excel(filename) 但我在真实文件名之前找到了 '~$'
- javascript - 当我将堆栈拆分为数组时,错误堆栈显示不同的信息
- html - 从网页处理 linux 用户密码过期
- c# - 在 C# 中使用 DI 登录到控制台
- intellij-idea - 如何替换 intellij 中的整行代码,其中行以公共前缀开头
- html - 没有 /public 后缀,Laravel 网页无法工作
- c# - 获取数组中字符串的索引列表?
- watchkit - WatchConnectivity transferFile 问题(手表-> iphone)
- javascript - 加载网页后是否可以禁用 JS 插件?
- c# - 如何识别 ChromeDriver 启动的 Chrome 进程?