gpt4 book ai didi

c# - 如何在 Net 5.0 版本中删除 '%AppName%.runtimeconfig.dev.json' 文件

转载 作者:行者123 更新时间:2023-12-05 05:53:53 24 4
gpt4 key购买 nike

我已经为 Net 5.0 创建了一个控制台应用程序并构建了它的发布版。在发布文件夹中,我发现了一些应用程序并不真正需要的文件(它在没有它们的情况下启动和工作):%AppName%.deps.json 和 %AppName%.runtimeconfig.dev.json。在第二个文件中,我找到了一些列表(名称为“additionalProbingPaths”),其中包含本地计算机上的三个绝对路径(其中两个甚至包含我的用户名)。显然,这些路径在将运行我的应用程序的任何其他机器上都没有用。我寻找一种方法来完全禁用生成此文件,但只发现:

<GenerateRuntimeConfigurationFiles>false</GenerateRuntimeConfigurationFiles>

但是这个选项禁止生成 %AppName%.runtimeconfig.json 并且我的可执行文件不工作。我也发现了这个 link (用于生成这些文件的 MSBuild 任务的源代码)。此任务包含两个 bool 选项:WriteAdditionalProbingPathsToMainConfig 和 GenerateRuntimeConfigDevFile。它们几乎就是我想要的,但我找不到通过项目文件的 PropertyGroup 设置此选项的方法。我试过:

<WriteAdditionalProbingPathsToMainConfig>true</WriteAdditionalProbingPathsToMainConfig>
<GenerateRuntimeConfigDevFile>false</GenerateRuntimeConfigDevFile>

但它不起作用。现在,我只需在 Post-Build Event 中通过 del 命令删除该文件。有什么方法可以防止生成该文件 (%AppName%.runtimeconfig.dev.json)?据我所知,这些“additionalProbingPaths”导致一些本地 nuget 存储库(但我的应用程序未安装任何 nuget 包!):

C:\\Users\\%UserName%\\.nuget\\packages
C:\\Users\\%UserName%\\.dotnet\\store\\|Arch|\\|tfm|

如果我的应用程序已经构建并准备好运行,他们需要做什么。或者最终应用程序用户需要下载一些包来运行我的应用程序?如果重要的话,我会使用 Visual Studio 2019。

P.S:很抱歉提出这样一个愚蠢的问题,但我是 Net Core 的新手。

最佳答案

没有将文件 %AppName%.runtimeconfig.dev.json 复制到发布目录是没有意义的,这应该是您打包/发送给最终用户的内容。

如果我通过 dotnet build -c Release 命令在发布版中构建默认应用程序,文件夹的内容如下:

Build folder content

但是,当我使用 dotnet publish -c Release 命令(唯一官方支持的准备部署应用程序的方法)时,文件夹的内容如下;你可以看到 %AppName%.runtimeconfig.dev.json 不存在:

Publish folder content

来自official documentation关于发布命令:

dotnet publish compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of files to a directory.
The dotnet publish command's output is ready for deployment to a hosting system (for example, a server, PC, Mac, laptop) for execution. It's the only officially supported way to prepare the application for deployment.

相比之下,official documentation关于构建命令:

The dotnet build command builds the project and its dependencies into a set of binaries.
(...) the product of dotnet build isn't ready to be transferred to another machine to run. To create a version of the application that can be deployed, you need to publish it (for example, with the dotnet publish command).

总结:不用担心 %AppName%.runtimeconfig.dev.json,而是使用 dotnet publish 命令。

关于c# - 如何在 Net 5.0 版本中删除 '%AppName%.runtimeconfig.dev.json' 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69810056/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com