是否可以将 .NET 5 项目设置为始终使用发布配置进行构建?

Can a .NET 5 project be set up to always build with release configuration?

我有一个小型 .NET 5 项目,其项目文件如下所示。

该项目将用于 运行 针对我的主要项目的性能基准。因此,我想始终使用 release 配置构建它。

documentation for the -c option of dotnet build command does say the following, but I haven't found any reference to it in the project file 部分:

The default for most projects is Debug, but you can override the build configuration settings in your project.

有没有办法在项目文件中指定它,而不是每次 运行 时都必须写 dotnet build -c release

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\src\Domain\Domain.fsproj" />
  </ItemGroup>
</Project>

是的,您可以将 <Configuration>Release</Configuration> 添加到 属性 组。见 corresponding MSBuild documentation.