Search code examples
c#.netvisual-studio.net-framework-versionbuild-error

How to resolve the error from changing target version of a project in a solution?


In the project I am currently working on, there are several projects in the solution. I had to change the target version of a particular project, which is responsible for handling particular APIs of the project, for installing certain Nuget Packages.

Now there are some .dll not found errors coming when I try to run the project.

How can I resolve this issue?
My project is based on .net framework and I am using Visual Studio 2017.

My actual Target version was .NET Framwork 4.5.1. I had to change it to 4.6.1 since the package I was trying to install IBM.Watson.NaturalLanguageUnderstanding.v1 -Version 4.2.1 package.

Errors are like this:

Metadata file 'location\ProjectName.dll' could not be found.


Solution

  • My actual Target version was .NET Framwork 4.5.1. I had to change it to 4.6.1 since the package I was trying to install IBM.Watson.NaturalLanguageUnderstanding.v1 -Version 4.2.1 package.

    I recreated the problem by attempting to install the nuget on a new console app targeting .netframework 4.6.1 and it failed

    This is where problem lies, IBM Watson NaturalLanguageUnderstanding is compatible with .NETStandard 2.0 Specification which means you would need to target 4.6.1 (*2) ideally, but here is the catch (as explained here MSDN)

    enter image description here




    2 ways to solve this

    • Target .NetFramework 4.7.1 as recommended by the MSDN above OR
    • If you want to use 4.6.1 then you would need to add this to your .CSPROJ file
    <PropertyGroup>
         .
         .
      <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
      <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
    </PropertyGroup>