'Blazor wasm build fails on Azure Devops (VSBuild task)

Since today my Azure Devops pipeline fails on the VSBuild task while it worked fine a long time.

I have 40 errors like :

##[error]BlazorClient\Components\AuditTrailList.razor.cs(17,19): Error CS0246: The type or namespace name 'ImportMessages' could not be found (are you missing a using directive or an assembly reference?)

ImportMessages that is referred in the error is actually a blazor component though which is located in the same project and the same namespace as AuditTrailList..

If I look closer at the 40 errors, it is always on components referring to other components, cfr. screenshot. enter image description here

This is my yaml file for the pipeline:

trigger:
  branches:
    include:
      - develop
  paths:
    exclude:
      - '**/azure-pipelines.yml'

pool:
  vmImage: 'windows-2022'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  JsLibDirectory: 'FundServices.BlazorClient/JsLib'

steps:
- task: UseDotNet@2
  displayName: 'Use dotnet 6'
  inputs:
    version: '6.0.x'
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'config'
    nugetConfigPath: '.nuget\NuGet.Config'
    externalFeedCredentials: 'Telerik Nuget'

- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- task: Npm@1
  displayName: 'npm install'
  inputs:
    command: 'install'
    workingDir: '$(JsLibDirectory)'
    verbose: true

- script: |
    npm run build
  displayName: 'npm run build'
  workingDirectory: '$(JsLibDirectory)'


- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    clean: true
    msbuildArchitecture: 'x64'

- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*Tests.dll
      !**\*TestAdapter.dll
      !**\obj\**
      !**\bin\**\ref\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(Build.artifactstagingdirectory)'
    zipAfterPublish: True

# - task: ExtractFiles@1
#   inputs:
#     archiveFilePatterns: '$(Build.artifactstagingdirectory)/FundServices.BlazorClient.zip'
#     destinationFolder: '$(Build.artifactstagingdirectory)/WorkingDirectory'
#     cleanDestinationFolder: true
#     overwriteExistingFiles: true

# - task: CopyFiles@2
#   inputs:
#     SourceFolder: '$(Build.artifactstagingdirectory)/WorkingDirectory/wwwroot'
#     Contents: 'web.config'
#     TargetFolder: '$(Build.artifactstagingdirectory)/WorkingDirectory'
#     OverWrite: true

# - task: ArchiveFiles@2
#   inputs:
#     rootFolderOrFile: '$(Build.artifactstagingdirectory)/WorkingDirectory'
#     includeRootFolder: false
#     archiveType: 'zip'
#     archiveFile: '$(Build.artifactstagingdirectory)/FundServices.BlazorClient.zip'
#     replaceExistingArchive: true

- task: PublishBuildArtifacts@1
  displayName: 'Publish WebApp'
  inputs:
    PathtoPublish: '$(Build.artifactstagingdirectory)/FundServices.BlazorClient.zip'
    ArtifactName: 'WebApp'
    publishLocation: 'Container'
  condition: succeededOrFailed()

- task: PublishBuildArtifacts@1
  displayName: 'Publish Api'
  inputs:
    PathtoPublish: '$(Build.artifactstagingdirectory)/FundServices.Api.zip'
    ArtifactName: 'WebApi'
    publishLocation: 'Container'
  condition: succeededOrFailed()


- task: PublishBuildArtifacts@1
  displayName: 'Publish WorkFlowScheduler'
  inputs:
    PathtoPublish: '$(Build.artifactstagingdirectory)/FundServices.WorkFlowScheduler.zip'
    ArtifactName: 'WorkFlowScheduler'
    publishLocation: 'Container'
  condition: succeededOrFailed()

Thanks, Tom



Solution 1:[1]

I had a very similar issue with my Web Api pipeline today, which worked fine last week. As mentioned above It was also caused by sdk '6.0.200' I have always used 'Use dotnet 6.0.x' that used to work fine, The solution was to specify the sdk version including the minor release, so 'Use dotnet 6.0.100' then it worked fine.

Solution 2:[2]

I've opened a case on this: https://github.com/dotnet/aspnetcore/issues/40333

Rolling back the SDK works, but if it helps, another work around suggested on the thread is to add a project reference to an older version of the code analysis package:
PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" PrivateAssets="all"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Patrick Butterworth
Solution 2 p2pbsh