解决build waring The parameter to the compiler is invalid, '/define:$(BUILDCONFIGURATION)' 在NET 6.0中会被忽略

Resolve the build waring The parameter to the compiler is invalid, '/define:$(BUILDCONFIGURATION)' will be ignored in NET 6.0

在我的管道构建 .yml 中,我有 buildConfiguration: "Release" 并在构建命令中使用它

task: DotNetCoreCLI@2
            displayName: Build
            inputs:
              command: build
              projects: "**/*.csproj"
              arguments: '--configuration $(buildConfiguration)

我得到了

6.0.101\Roslyn\Microsoft.CSharp.Core.targets(75,5): Warning MSB3052: The parameter to the compiler is invalid, '/define:$(BUILDCONFIGURATION)' will be ignored.

在 NET 6.0 构建中。有任何修复此警告的建议吗?

Resolve the build waring The parameter to the compiler is invalid, '/define:$(BUILDCONFIGURATION)' will be ignored in NET 6.0

由于您无法共享整个 YAML 文件,要解决此问题需要您进行更多故障排除。

作为建议,您可以尝试将变量更改为特定值以测试问题是否仍然存在,而不是 $(buildConfiguration)release:

- task: DotNetCoreCLI@2
  displayName: 'Build'
  inputs:
    command: build
    projects: Net6Test/Net6Test/Net6Test.csproj
    arguments: '--configuration release'

作为测试,我创建了一个 .NET 6 示例项目,并使用以下 YAML 脚本构建它,它工作正常:

pool:
  name: xxxx

variables:
  buildConfiguration: 'Release'

steps:
- task: DotNetCoreCLI@2
  displayName: 'Build'
  inputs:
    command: build
    projects: Net6Test/Net6Test/Net6Test.csproj
    arguments: '--configuration $(buildConfiguration)'

我通过更新管道

解决了上述构建问题