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 some series of detailed posts for the same in future but just wanted to share the resolution for an error which I faced today.
Short description of what am I doing
- 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
Here comes the challenging part – The windows agent, on which we are gonna build our projects, has Visual Studio 2017 along with all required tooling. So the projects which are under VS 2015, 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 on 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 the 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 thing came because I thought 4.5.1 is also present on the Windows agent.
After much struggles and different tries(more than 200 builds on agent) – I finally got a solution which helped me to get rid of 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″‘
- Make sure you have required sdk installed on your agent and if not then install it first, no need to install whole VS 2015 – just 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 full and final solution to allow your regular .Net project to build with latest VS 2017 tooling, it is just a solution to above error
As I said there are still many things to do so I will write some more posts in future on these topics.
PS – Start restructuring your normal csproj code to latest sdk structure which will help you to onboard your applications with latest and powerful VS 2017 tools.
Hope it helps.