Skip to content

.NET Core SDK 6.0.200: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0' #23972

@pmalmsten

Description

@pmalmsten

Describe the bug

Build fails with error:
##[error]CSC(0,0): Error CS8032: An instance of analyzer Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator cannot be created from C:\hostedtoolcache\windows\dotnet\sdk\6.0.200\Sdks\Microsoft.NET.Sdk.Razor\source-generators\Microsoft.NET.Sdk.Razor.SourceGenerators.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
when using .NET Core SDK 6.0.200 with Visual Studio 2022 on Azure DevOps Microsoft-Hosted Agent.

Error goes away after reverting to .NET Core SDK 6.0.102.

I was unable to reproduce this on my personal Windows 11 machine using Visual Studio 2022 (with latest updates) and running a build command very similar to what Azure DevOps does: "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\msbuild.exe" "C:\Users\paulmalmsten\source\repos\Terrapin\PackageRebuilder.sln" /nologo /nr:false -m /p:configuration="debug" /p:VisualStudioVersion="17.0" /p:_MSDeployUserAgent="VSTS_011b8bdf-6d56-4f87-be0d-0092136884d9_build_11835_0"

Azure DevOps image version where this was observed: https://github.com/actions/virtual-environments/releases/tag/win22%2F20220207.1

To Reproduce

I was able to reproduce this issue on a template Web App project created by Visual Studio 2022 without modification.

Steps:

  1. Follow these instructions for creating a Web App project from a template.
  2. Check the project into Git (in my example, under the WebApplication1 directory below the git repository root), push to a branch in Azure Dev Ops.
  3. Configure an Azure DevOps Pipeline which runs on windows-2022 having the following steps:
- task: NuGetToolInstaller@1
  displayName: 'Install NuGet 6.x'
  inputs:
    versionSpec: 6.x

- task: UseDotNet@2
  displayName: 'Add .NET 5.0'  
  inputs:
    packageType: 'sdk'
    version: '5.0.x'

- task: UseDotNet@2
  displayName: 'Add .NET 6.0'  
  inputs:
    packageType: 'sdk'
    version: '6.0.x'

- task: NuGetCommand@2
  displayName: 'NuGet Restore'
  inputs:
    restoreSolution: '$(Build.SourcesDirectory)\WebApplication1\WebApplication1.sln'

- task: VSBuild@1
  displayName: 'Build the solution'
  inputs:
    solution: '$(Build.SourcesDirectory)\WebApplication1\WebApplication1.sln'
    configuration: 'debug'
    msbuildArgs: '-m'
  1. Run the Azure DevOps Pipeline.

Expected Result: Compiles successfully.
Actual result: Error message seen above.

Exceptions (if any)

Not applicable.

Further technical details

  • Include the output of dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.200
 Commit:    4c30de7899

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.20348
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\hostedtoolcache\windows\dotnet\sdk\6.0.200\

Host (useful for support):
  Version: 6.0.2
  Commit:  839cdfb0ec

.NET SDKs installed:
  5.0.405 [C:\hostedtoolcache\windows\dotnet\sdk]
  6.0.200 [C:\hostedtoolcache\windows\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.14 [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.2 [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.14 [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.2 [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.14 [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.2 [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version

Not applicable. Error happens on Azure DevOps hosted agent.

Metadata

Metadata

Assignees

Labels

Area-AspNetCoreRazorSDK, BlazorWebAssemblySDK, StaticWebAssetsSDK

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions