c# - dotnet 构建应用程序部署

标签 c# build .net-core asp.net-core-webapi

我们有一个 .net 核心 Web 应用程序,我们正在构建一个自动部署过程。根据我在 this site 上阅读的内容,我已经看到了:

the product of dotnet build isn't ready to be transferred to another machine to run. This is in contrast to the behavior of the .NET Framework in which building an executable project (an application) produces output that's runnable on any machine where the .NET Framework is installed.

因此,如果我在目标机器上安装了 .net 核心运行时,是否可以使用构建命令的输出?因为使用此命令,输出不包含额外的文件夹(本地化 dll、运行时文件夹等)...

此外,是否有一个参数可以与 dotnet build 命令一起使用,以便在输出文件夹中只有 MyStartupProject.runtimeconfig.json 而不是所有 runtimeconfig.json 文件(来自所有项目以及 runtimeconfig.json 的版本)。 dev.json)?

最佳答案

tl;dr

dotnet publish会做你想做的


dotnet publish command将对您的应用程序进行完整打包,准备好在 UAT 或生产环境中运行。

请注意

上一段中的链接.NET Core 2.x,但是.NET Core 1.x 的过程非常相似。链接页面在一系列选项卡中包含针对 .NET Core 1.x 和 2.x 的说明。

发布命令有几个可能的参数,这取决于您希望如何托管您的应用程序。例如--self-contained会将相关的 .NET Core 运行时与您的应用程序打包在一起,这样它就可以“按原样”推送到服务器,而无需安装运行时。

-r|--runtime <RUNTIME_IDENTIFIER>也很有用。文档(前面有链接)按以下方式对其进行了解释

Publishes the application for a given runtime. This is used when creating a self-contained deployment (SCD). For a list of Runtime Identifiers (RIDs), see the RID catalog. Default is to publish a framework-dependent deployment (FDD).

您还需要考虑使用 --configuration开关,提供 DebugRelease - 最好是 Release .这基本上与在 Visual Studio 中的调试或发布中构建相同,只是这将在发布操作之前发生。

这是对 dotnet publish 的描述官方文档中的命令:

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 output will contain the following:

  • Intermediate Language (IL) code in an assembly with a dll extension.
  • .deps.json file that contains all of the dependencies of the project.
  • .runtime.config.json file that specifies the shared runtime that the application expects, as well as other configuration options for the runtime (for example, garbage collection type).

The application's dependencies. These are copied from the NuGet cache into the output folder.

The dotnet publish command's output is ready for deployment to a hosting system (for example, a server, PC, Mac, laptop) for execution and is the only officially supported way to prepare the application for deployment. Depending on the type of deployment that the project specifies, the hosting system may or may not have the .NET Core shared runtime installed on it. For more information, see .NET Core Application Deployment. For the directory structure of a published application, see Directory structure.

关于c# - dotnet 构建应用程序部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48537869/

相关文章:

.net-core - 无法将 EntityFrameworkCore 工具添加到 Visual Studio 2017 中的类库

c# - 用对象数组修补对象

c# - 错误 :The preLaunchTask 'build' terminated with exit code 1

c# - 智能表日期格式是什么?

c# - 有没有办法禁用或修改 .NET XML 解析器的严格性?

ios - 如何在没有 xcode 的情况下生成 xml 格式的权利?

docker - ASP .NET Core 在 Heroku 上给出 System.Net.Sockets.SocketException 错误

c# - 没有等待的异步编程?

java - Jenkins 工作区管理

php - 使用 ant 脚本构建 PHP