20

I have an Azure pipeline setup for my builds. I have been running into this issue recently and cannot figure out a way to fix this:

##[error]C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1220,5): Error MSB3644: The reference assemblies for .NETFramework,Version=v4.6.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

About a week or so ago lots of our builds were failing, MS had changed something and we were getting this sort of thing:

[error]C:\Users\VssAdministrator\.nuget\packages\codegeneration.roslyn.buildtime\0.6.1\build\CodeGeneration.Roslyn.BuildTime.targets(73,5): Error CGR1001: CodeGeneration.Roslyn.Tool (dotnet-codegen) is not available, code generation won't run. Please check https://github.com/AArnott/CodeGeneration.Roslyn for usage instructions. 

However was able to solve this by explicitily adding a task to include the netcore2.1 sdk

    - task: UseDotNet@2
      inputs:
        packageType: 'sdk'
        version: '2.x'

Now this issues is fixed we are now posed with the error complaining it cannot find .NET Framework 4.6.1.

Anyways any idea whats going on, this is driving me banannas - any advice or insight greatly appreciated.

ree6
  • 383
  • 2
  • 13
  • 1
    This might sound obvious, but did you check that *all* of your build agents supporting 4.6.1? That's a very old version of .NET so it may be as simple as adding that back. – Kit Mar 15 '22 at 17:45
  • Thanks @Kit - how do you check that I will look into it? – ree6 Mar 15 '22 at 19:54
  • In the past I've remoted into and inspected the server(s) or container(s) the agents run on to see if they have the required setup/SDKs. I wish I could be more specific but I'm not using Azure DevOps these days. – Kit Mar 15 '22 at 21:22

2 Answers2

26

The .Net framework version 4.6.1 has been deprecated by Azure DevOps Microsoft-hosted agent. For now, there are two kinds of Microsoft-hosted agents:

windows-2019 OR windows-latest: .Net framework version 4.7.2 and 4.8 preinstalled. This is documented here.

windows-2022: .Net framework version 4.8 preinstalled. This is documented here.

That is, you need to use self-hosted agent to use .Net framework 4.6.1 in the pipeline.

Jane Ma-MSFT
  • 4,461
  • 1
  • 6
  • 12
  • 3
    Whilst this is mostly accurate, you can change the agent specification of a windows hosted agent in the agent pool to run Windows-2019 and this will address the issue. This is documented [here](https://blog.novacare.no/devops-change-agent-specification-to-windows-latest/) – Bmize729 Mar 23 '22 at 07:14
  • 5
    vmImage: 'windows-2019' in the yml worked with 4.6.1 for me, so no need to use a self-hosted agent. – Daniel Bailey Mar 25 '22 at 10:25
  • vmImage: 'windows-2019' still working for .Net Framework 4.6.1 – Francois du Plessis Jun 30 '22 at 09:28
11

From Agent pool - Change Agent Specification from Window-Latest to Window-2019 ,It seems MS has done some changes in default agent

Pipeline setting

JeremyW
  • 5,157
  • 6
  • 29
  • 30
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 16 '22 at 14:56
  • 7
    Specifically, updating the azure-pipelines.yml **pool** configuration section for the Pipeline to `vmImage: 'windows-2019'` from `vmImage: 'windows-latest'` resolved the issue for me – Wungsow Mar 21 '22 at 05:44