.netazure-devopsazure-pipelinesazure-pipelines-build-taskazure-pipelines-tasks

Azure Pipelines fail while MSBuild@1 (or VSBuild@1) The reference assemblies for .NETFramework,Version=v4.0 were not found


I used Azure Data Studio to build a sql project into an .sqlproj file which looks like that:

<?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>

I use Azure Pipelines (windows agent) to build the .sqlproj file using the MSBuild@1 (or VSBuild@1) task:

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

Pipeline logs this error messsage:

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]

Solution

  • After posting the same thread on GitHub, I was suggested, and it actually worked to use the DotNetCoreCLI@2:

              - task: DotNetCoreCLI@2
                displayName: 'Build Project: *.sqlproj'
                inputs:
                  command: 'build'
                  projects: '**\*.sqlproj'
    

    instead of MSBuild@1 (or VSBuild@1).

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

    https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/dotnet-core-cli-v2?view=azure-pipelines