0

My solution uses the latest version of .net which is 4.8. However, I see the following error message that complaints about a version 4.0 in Azure Pipelines. Can someone let me know how I could resolve this please ?

The error message indicates I need to install 4.0 but I don't think that's the solution. I also opened up the file Microsoft.Common.CurrentVersion.targets and line 1221 has the following. However, I know it is not advisable to edit this file.

<!-- By default if there is no root path set then the task will assume it is Program Files\Reference Assemblies\Microsoft\Framework-->
<GetReferenceAssemblyPaths
    Condition="'$(TargetFrameworkMoniker)' != '' and ('$(_TargetFrameworkDirectories)' == '' or '$(_FullFrameworkReferenceAssemblyPaths)' == '')"
    TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
    RootPath="$(TargetFrameworkRootPath)"
    TargetFrameworkFallbackSearchPaths="$(TargetFrameworkFallbackSearchPaths)"
    BypassFrameworkInstallChecks="$(BypassFrameworkInstallChecks)"
    >
  <Output TaskParameter="ReferenceAssemblyPaths" PropertyName="_TargetFrameworkDirectories"/>
  <Output TaskParameter="FullFrameworkReferenceAssemblyPaths" PropertyName="_FullFrameworkReferenceAssemblyPaths"/>
  <Output TaskParameter="TargetFrameworkMonikerDisplayName" PropertyName="TargetFrameworkMonikerDisplayName" Condition="'$(TargetFrameworkMonikerDisplayName)' == ''"/>
</GetReferenceAssemblyPaths>

The error message:

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1221,5): 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 your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

Note: There are many similar post in SO that suggest to install VS2019. However, I am getting this message while running the application on Azure Pipelines.

Update

enter image description here

Illep
  • 16,375
  • 46
  • 171
  • 302
  • What task do you use to build the solution on the pipeline? – Artem May 28 '22 at 04:55
  • @Artem task: VSBuild@1 – Illep May 28 '22 at 04:56
  • I already have installed visual studio 2019 and 2022 on my local machine. – Illep May 28 '22 at 04:58
  • @MickyD Look at the attached screenshot. I don't see a .net framework 4 there. – Illep May 28 '22 at 05:08
  • 1
    No. its just a standard project. – Illep May 28 '22 at 05:09
  • What folders do you see here: **C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework** ? –  May 28 '22 at 05:21
  • Is this a private agent pool? –  May 28 '22 at 05:29
  • Does this answer your question? [The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found](https://stackoverflow.com/questions/44548780/the-reference-assemblies-for-framework-netframework-version-v4-6-2-were-not-f) –  May 28 '22 at 05:37
  • I see 4.0, 4.x, 3.5 , 4.5 and a whole lot more. – Illep May 28 '22 at 05:40
  • @Illep VSBuild@1 allows to specify a concrete VS version as a parameter: (example: #vsVersion: '15.0'). If I were you I'd play with that. Also what's worth trying is to run the pipeline on different agents. If you use a default image of windows-latest, you may set specific versions, like windows-2019 or windows-2017. – Artem May 28 '22 at 06:13
  • @Artem that didn't help either. – Illep May 28 '22 at 07:54
  • *I already have installed visual studio 2019 and 2022 on my local machine.*. Are you using your local machine as a build agent? If not, installing Visual Studio on your local machine has no impact. Please provide more detail on your build infrastructure. Are you using Microsoft hosted agents, or self-hosted agents? – Daniel Mann May 29 '22 at 00:57
  • @DanielMann I am using Microsoft hosted agents. I am new to this, therefore, kindly guide me of what information required to debug the issue. – Illep May 29 '22 at 13:13
  • What about using self host agent, will it works? – Bowman Zhu-MSFT Jun 01 '22 at 06:03

1 Answers1

2

From your description, you are using the Microsoft host agent and the pipeline pop out issue 'cannot found NETFramework,Version=v4.0'.

Your environment looks like this:

https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#net-framework

or

https://github.com/actions/virtual-environments/blob/main/images/win/Windows2022-Readme.md#net-framework

You can see that the Microsoft host agent does not have the environment you mentioned.

Although you can install what you need at the beginning of the pipeline startup, I do not recommend this practice. Because when you choose microsoft host agent, every time you start the pipeline, you will be assigned a brand new azure VM machine, which means you need to install the relevant environment every time.

The recommended approach is to use a self-host agent. Please create a self-host agent based on your local machine (or another machine with the relevant environment), the steps are as follows:

https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops

Provided above are the installation steps of windows self host agent, the steps should be very simple, if you encounter any problems please let me know.

And after that, you can run your pipeline based on that self host agent like this:

pool:
  name: <your agent pool name>

If you are using classic pipeline, just click and select:

enter image description here

(If you run successfully on local, then the agent based on local machine should also be no problem.)

And if this is still unable to solve your issue, could you please remove the in-private information and share the YAML file or JSON file, and let me know at which step you encountered this issue?

Bowman Zhu-MSFT
  • 4,776
  • 1
  • 9
  • 10