Error MSB3644: The reference assemblies for framework “.NETFramework,Version=v5.0” were not found.

.NET 5.0 is now available and you might want to upgrade or include the new target framework within your continuous integration. If your CD features a self-hosted Agent, this article might be the wrong place to look for an answer, as we only cover the Hosted VS2017 pool.

Remark: This workaround only works for .NET Core applications targeting .NET 5.0

Build .NET Core against .NET 5.0

The hosted VS2017 agent is free but does not comprise the .NET 5.0 SDK on all agents currently.

Hosted VS2017 Agent

Thus, you might receive following exception while targeting the new .NET Framework 5.0 SDK.

##[error]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1179,5): 
Error MSB3644: The reference assemblies for framework ".NETFramework,Version=v5.0" were not found. 
To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. 
Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. 
Therefore your assembly may not be correctly targeted for the framework you intend. 

As long as not all agents do support the new SDK, we require to apply a slight workaround: Installing the SDK on demand and adding it to the path’s environment.

Add .NET50 SDK to the Build’s environment

Edit your pipeline and add a new task, so called “Use .NET Core”. Ensure that the task will be executed before your actual build task.

Build Task: “Use .NET Core”

Configure the Build task

Click on the “Use .NET Core” task within the Agent’s jobs and apply following settings.

After the configuration, your Task’s YAML should look like

steps:
 task: UseDotNet@2
 displayName: 'Use .NET 50 SDK'
 inputs:
 version: 5.x
 includePreviewVersions: true
 performMultiLevelLookup: true 

Save, queue and everything should build as expected.

Keep an eye on the agent images

Microsoft will release new agent images supporting .NET 5.0 natively. (Calendar Week 46). Current supported SDKs can be found here. Disable or remove the workaround as soon as the Visual Studio version hits 16.8.0.

0 0 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments