Illep
Illep

Reputation: 16841

Azure Pipelines unable to find .Net framework version 4.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

Upvotes: 0

Views: 5382

Answers (1)

Bowman Zhu
Bowman Zhu

Reputation: 7146

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?

Upvotes: 2

Related Questions