Over a million developers have joined DZone.

How I Resolved the Error ''The Reference Assemblies for Framework 'v4.5.1' Were Not Found''

DZone's Guide to

How I Resolved the Error ''The Reference Assemblies for Framework 'v4.5.1' Were Not Found''

If you've come across this issue while programming your .NET projects in Windows, then this post might have your answer.

· DevOps Zone ·
Free Resource

Can you release faster without sacrificing quality? See how with our free ebook Strategies for a Successful Test Automation Project and a free trial of Ranorex Studio today!

Nowadays, I am experimenting a lot to implement CI\CD for all our .Net projects along with BitBucket(Git), Jenkins, Sonar, Fortify, Visual Studio 2017 tools, Artifactory, Dev cloud, VMs, Docker, and many more.

I will post a series of detailed posts for this in the future, but I just wanted to share the resolution for an error which I faced today.

So, basically:
  • We have a bunch of .Net projects under one solution.
  • These projects are mainly .Net version 4.5.1.
  • The first step is to build these projects on Jenkins using a Windows agent.

The Challenge

Here comes the challenging part - the Windows agent on which we are going to build our projects, has Visual Studio 2017 along with all required tooling. So the projects which are under VS 2015, but we want them to build with VS 2017 build tools

The challenge is to build our normal .Net projects with Visual Studio 2017 MSBuild, which generally resides in the location C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe.

Now, when I try to build a big solution (which has around 30 projects) with VS 2017 MSBuild, it throws this error:

The reference assemblies for framework ".NETFramework,Version=v4.5.1" 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.

I was wondering why this happened, because I thought 4.5.1 was also present on the Windows agent.

The Solution

After much struggling and different tries (more than 200 builds on the agent), I finally found a solution which helped me  get rid of the above error. The solution which worked for me was to add FrameworkPathOverride as a parameter along with your MSBuild commands.

So basically the command would look like:

bat '"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\MSBuild\\15.0\\Bin\\MSBuild.exe" MySolutionName.sln /p:Configuration=Debug /p:Platform=\"Any CPU\" - p:FrameworkPathOverride="C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5″'

Important Notes:
  • Make sure you have the required sdk installed on your agent; if not, install it first, no need to install the whole VS 2015 - just the sdk should work.
  • Note that the path may change in your case. I just pasted the path which worked for me.
  • Also, this is not a full and final solution to allow your regular .Net project to build with the latest VS 2017 tooling, it is just a solution to the above error.

As I said, there are still many things to do, so I will write some more posts in the future on these topics.

P.S. Start restructuring your normal csproj code to latest sdk structure, which will help you to onboard your applications with the latest powerful VS 2017 tools.

Helpful link: Old csproj to new csproj: Visual Studio 2017 upgrade guide.

Hope it helps.

Get your test automation project off to the right start. Download your free test planning template and a 30-day no-obligation trial of Ranorex Studio today!

devops ,.net ,ci/cd ,errors ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}