Pages

Monday, October 1, 2018

Referencing .NET 4.5 dll in .NET Core csproj

Hi All,

After a long time, I realized that I need to share something with the outer world.

Since we are inside the .Net core world and things are moving fast towards making the .Net 4 and pre .Net 4 obsolete. Let's try something that do not have much on the internet.


I have a .Net 4.5.2 application. I had to create a new console application in the solution to do some scheduling (not windows service, obviously). I went ahead and took the pleasure of doing it .Net Core. The latest version by the time of this writing is .Net core 2.1.

I stumbled upon a series of problems with .Net Core, so I thought it might be helpful for others as well, if I posted about those here...

When I created a new project and added a reference for .Net 452 project inside the console application, it went smooth and everything built alright, but as soon as I tried to run the console application it started crashing on the first .Net 452 reference inside the project structure. In my case, it was "System.Configuration".

It was a default error saying... 
System.IO.FileNotFoundException: 'Could not load file or assembly _ _ _. The system cannot find the file specified.'
So, what do I do, I went to Google and tried to find the problem, the first post that I could find was this one by Scott Hanselmann.

But this was not my problem, as this post was related to Nuget Packages, not related to normal assembly reference. After a little more searching I was able to find this StackOverflow Post. which is quite close to my problem.

I only had to modify the CSProj and set the TargetFramework to multiple frameworks as the VS 2017 UI does not allow me to do that...

So, I had to go to another editor or unload the project from visual studio and edit the csproj file. But I prefer VS Code, which is super fast to load and very good tool to help with these kind of operations. I would recommend opening both the editors in parallel on a development machine.

Anyways, I had to add to change this tag in the csproj file...
<TargetFrameworks>net452;netcoreapp1.1</TargetFrameworks>

Notice the change from the <targetframework> to <targetframeworks>, an additional 's' for multiple Frameworks support with .Net Core.

One more thing to care about, you might need to give the specific version of .Net Framework that you are using in other projects, like in above example it is 4.5.2

This is it... Happing Coding... 


No comments:

Post a Comment