You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何执行dotnet publish命令会生成两份相同文件?

Why Duplicate Files Appear After dotnet publish in .NET Core 2.x

Great question—this is actually a quirk of how the dotnet publish command worked in .NET Core 2.x when targeting a specific runtime. Let me break it down clearly:

  • When you run dotnet publish --configuration Release --runtime win-x64, the command does two distinct things under the hood:
    1. It first runs a runtime-targeted build, outputting compiled assemblies and native runtime dependencies to bin\Release\netcoreapp2.0\win-x64. This is an intermediate build artifact, designed for framework-dependent deployment (meaning the target machine still needs the .NET Core Runtime installed to run the app).
    2. It then generates a production-ready deployment package in the win-x64\publish subdirectory. For .NET Core 2.x, specifying a runtime makes this package self-contained—it includes all required .NET Core runtime files, so the app can run on Windows machines without pre-installed .NET Core.

While the file lists might look identical at first glance, their purposes differ:

  • The outer win-x64 directory is a byproduct of the build step, useful only for local testing of framework-dependent builds.
  • The publish subdirectory is the actual bundle you should use for deploying your app to production or other machines.

This confusing duplicate output was fixed in later .NET versions (3.0 and above), where dotnet publish no longer generates the intermediate outer directory—instead, it directly outputs only the publish-ready files to avoid clutter.

In short: this is just a .NET Core 2.x-specific behavior, and you can safely ignore or delete the outer win-x64 directory if you're focused on deploying your app.

内容的提问来源于stack exchange,提问作者Kirsten

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:20:35