为什么会创建“net6.0-windows”子文件夹?

Pos*_*ity 18 .net visual-studio winforms .net-5 .net-6.0

我正在使用 Visual Studio 2022 并创建了一个 winforms .net 6 应用程序。我为我的发布版本指定了一个输出路径,我希望在其中创建 .exe,但 Visual Studio 创建了一个名为“net6.0-windows”的子文件夹并将 exe 放入其中。我该如何停止它并让它将 exe 放在我指定的位置?

一些背景:我正在将 .Net Framework 4.8 Winforms 升级到 .Net 6。在 .net Framework 中,它将 exe 放在指定的输出文件夹中(无子文件夹)。我想保持相同的行为,因为其他文件和实用程序也需要位于其中或查看该文件夹。

Visual Studio中指定的输出路径

[Visual Studio中指定的输出路径]

实际输出路径

[实际输出路径]

Chr*_*n.K 31

我将提供以下信息供参考和回答问题。

您可以通过将以下属性添加到项目文件来防止将 TargetFramework 添加到输出文件夹。

<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
Run Code Online (Sandbox Code Playgroud)

此外,您可以阻止添加 RuntimeIndentifier(例如win-x64)(如果有),将此属性设置为 false:

<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
Run Code Online (Sandbox Code Playgroud)

你应该这样做吗?

也许不会。这些目录的存在是有原因的:允许多个 TargetFramework(版本)和/或多个 RuntimeIndentifier 并行(否则输出将以不正当的方式混合)。