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

Azure DevOps CI流水线构建遇NETSDK1129错误求助

解决Azure DevOps CI流水线中的NETSDK1129错误

错误NETSDK1129: 未指定目标框架时不支持“Publish”目标的核心原因是你的项目配置了多个目标框架(在.csproj文件中使用<TargetFrameworks>复数节点,比如<TargetFrameworks>net6.0;net7.0</TargetFrameworks>),发布时构建系统无法自动确定要使用哪个框架,必须显式指定。

解决方案1:指定单个目标框架发布

在DotNetCoreCLI@2的publish任务中,通过--framework参数明确指定要发布的框架版本,同时可以将目标框架定义为变量方便维护:

trigger:
- none

pool:
  name: default

variables:
  solution: '**/*.sln'
  project: '**/*.csproj'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  targetFramework: 'net6.0' # 替换为你需要发布的框架版本

steps:
- task: NuGetToolInstaller@1
  displayName: NuGetTool Installer
  inputs:
    versionSpec: '4.9.6' 
    checkLatest: true

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '$(solution)'
    feedsToUse: 'select'

- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: '$(project)'
    arguments: '--configuration $(buildConfiguration) --framework $(targetFramework) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: false

解决方案2:发布所有目标框架

如果需要发布项目配置的所有目标框架,可使用foreach参数让任务遍历每个框架,并将每个框架的输出文件放到独立子目录中,避免文件冲突:

trigger:
- none

pool:
  name: default

variables:
  solution: '**/*.sln'
  project: '**/*.csproj'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1
  displayName: NuGetTool Installer
  inputs:
    versionSpec: '4.9.6' 
    checkLatest: true

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '$(solution)'
    feedsToUse: 'select'

- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: '$(project)'
    arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/$(TargetFramework)'
    zipAfterPublish: false
    foreach: 'TargetFramework'

额外检查

确认你的.csproj文件中是否存在<TargetFrameworks>(复数)节点,如果是单个框架应使用<TargetFramework>(单数)节点,这样发布时无需额外指定框架参数。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 02:33:27