为何DotNetCoreCLI@2任务仅构建Debug版本?
原因分析与解决方案
核心原因
你定义的buildConfiguration变量并没有被DotNetCoreCLI@2的publish任务自动应用。虽然管道里声明了这个变量,但dotnet publish命令默认采用Debug作为构建配置,除非你显式指定。从日志里的执行命令能看出,dotnet publish完全没带--configuration Release参数,所以MSBuild自然用了默认的Debug配置编译发布。
解决办法
有两种可行的修正方式:
1. 在arguments中显式添加配置参数
修改DotNetCoreCLI@2任务的arguments,加入--configuration $(buildConfiguration):
- task: DotNetCoreCLI@2 inputs: command: 'publish' publishWebProjects: false projects: '**/*.csproj' arguments: '--configuration $(buildConfiguration) -o $(Build.ArtifactStagingDirectory)/Output' zipAfterPublish: true modifyOutputPath: true
2. 使用任务自带的configuration输入项
DotNetCoreCLI@2任务本身提供了configuration输入参数,直接指定即可,无需写在arguments里:
- task: DotNetCoreCLI@2 inputs: command: 'publish' publishWebProjects: false projects: '**/*.csproj' configuration: $(buildConfiguration) arguments: '-o $(Build.ArtifactStagingDirectory)/Output' zipAfterPublish: true modifyOutputPath: true
验证方式
修改后重新运行管道,查看日志中的dotnet publish命令,应该会包含--configuration Release参数,构建输出的dll路径也会变为bin/Release/net6.0/,再用Ildasm验证就能看到AssemblyConfigurationAttribute的值为Release。
内容的提问来源于stack exchange,提问作者Neutrino
相关产品推荐
相关产品推荐

