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

Azure Pipelines中MSBuild@1/VSBuild@1构建sqlproj时缺少.NET 4.0引用程序集报错

解决Azure Pipelines构建SQL项目时的.NET Framework 4.0依赖问题

问题场景

你使用Azure Data Studio创建了SQL项目,生成的.sqlproj文件内容如下:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build">
  <Sdk Name="Microsoft.Build.Sql" Version="0.1.12-preview" />
  <PropertyGroup>
    <Name>SOmeName</Name>
    <ProjectGuid>{xxxx-xxxxx}</ProjectGuid>
    <DSP>Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider</DSP>
    <ModelCollation>1033, CI</ModelCollation>
  </PropertyGroup>
  <ItemGroup>
    <Folder Include="TestSchema" />
  </ItemGroup>
  <Target Name="BeforeBuild">
    <Delete Files="$(BaseIntermediateOutputPath)\project.assets.json" />
  </Target>
</Project>

随后你在Azure Pipelines的Windows代理上,通过MSBuild@1或VSBuild@1任务构建该项目,任务配置如下:

- task: MSBuild@1 # 或VSBuild@1
  displayName: 'Build Project: *.sqlproj'
  inputs:
    solution: '**\*.sqlproj'
    platform: 'Any CPU'
    configuration: Release

构建时出现以下错误:

error MSB3644: The reference assemblies for .NETFramework,Version=v4.0 were not found.
To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework
version or retarget yourapplication. You can download .NET Framework Developer Packs
at https://aka.ms/msbuild/developerpacks [C:\a\10\s\blabla]

解决方案

方案1:在Pipeline中安装.NET Framework 4.0开发包

通过Chocolatey工具在代理机器上安装.NET Framework 4.0开发包,在构建任务前添加以下步骤:

- task: ChocolateyCommand@0
  displayName: 'Install .NET Framework 4.0 Developer Pack'
  inputs:
    command: 'install'
    installPackageId: 'dotnetfx-4.0-devpack'
    allowEmptyChecksums: true

方案2:升级Microsoft.Build.Sql SDK版本

你当前使用的是预览版0.1.12-preview,该版本依赖.NET Framework 4.0。升级到最新稳定版的SDK,可避免对旧版本.NET Framework的依赖。修改.sqlproj文件中的SDK版本:

<Sdk Name="Microsoft.Build.Sql" Version="1.2.0" />

(注:可根据实际情况使用最新稳定版本号)

方案3:使用Visual Studio构建工具并指定版本

如果使用VSBuild@1任务,指定使用较新版本的Visual Studio构建工具,这类工具通常已包含所需的.NET Framework目标包。修改任务配置:

- task: VSBuild@1
  displayName: 'Build Project: *.sqlproj'
  inputs:
    solution: '**\*.sqlproj'
    platform: 'Any CPU'
    configuration: Release
    vsVersion: 'latest'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 14:12:10