错误消息NETSDK1129:不支持在未指定目标框架的情况下发布目标,项目面向多个框架

error msg NETSDK1129:Publish target is not supported without specifying a target framework, project is targeting multiple frameworks

提问人:Mayur Panchale 提问时间:11/17/2023 最后编辑:Kevin Lu-MSFTMayur Panchale 更新时间:11/17/2023 访问量:37

问:

我在 Azure devOps 中构建 CI 管道时收到此错误 错误消息NETSDK1129:在未指定目标框架的情况下,不支持“发布”目标,这表明您的项目面向多个框架,并且在发布过程中,生成系统无法确定要用于发布的框架。

这是我的YAML文件

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)'
    zipAfterPublish: false
asp.net azure-devops 持续集成 azure-pipelines net-4.8

评论

0赞 Kevin Lu-MSFT 11/27/2023
这张票有什么更新吗?如果答案可以给您一些帮助,请随时让我知道

答:

0赞 Kevin Lu-MSFT 11/17/2023 #1

NETSDK1129:不支持“发布”目标,除非指定目标框架,则表明您的项目面向多个框架

Dotnet publish 不支持同时使用多个 TargetFramework。

您可以检查 csproj 文件中的 TargetFrameworks 字段,并确认它们是否正在使用 TargetFrameworks

例如:

  <PropertyGroup>
    <TargetFrameworks>net5.0;net48</TargetFrameworks>
  </PropertyGroup>

可以在 dotnet publish 任务中添加参数:--framework xxx 来定义单个目标框架。

例如:

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