amine aloui
amine aloui

Reputation: 23

.NET Core transitive Dependency for a .NET 4.6 Project

I have three .NET projects referencing each other like the following:

AProject-> BProject-> CProject, where A and B are Core projects and C is a .NET 4.6 project.

AProject json file:

{
  "version": "1.0.0-*",
  "frameworks": {
   "net46": {
    "dependencies": {
    "ProjectB": {
      "target": "project" 
        }
      }
    }
  }
}

BProject json file:

{
  "version": "1.0.0-*",
  "frameworks": {
   "net46": {
    "dependencies": {
    "ProjectC": {
      "target": "project" 
        }
      }
    }
  }
}

NuGet restore and build work fine using Visual Studio, but NuGet restore using command line fails with the following error:

 Unable to resolve 'CProject' for '.NETFramework,Version=v4.6'

Remark: if i remove AProject from solution or if i change Cproject with another .NET core project, everything works fine. So the problem only occurs when we have a transitive dependency toward .NET 4.6 project.

Environment :

- NuGet Version: 3.5.0.1996
- Visual studio 2015
- .NET Core  1.0.1

Upvotes: 2

Views: 679

Answers (2)

Leo Liu
Leo Liu

Reputation: 76670

I could completely reproduced your problem in my environment. NuGet restore package base on packages.config file, or a project.json file. NuGet will check the packages.config/project.json files in each projects when we restore the .sln file using NuGet command line.

For this structure AProject-> BProject-> CProject, NuGet will restore the packages for the Aproject base on the projectA.json. But only the dependencie “ProjectB” be defined in the ProjectA.json file, the dependencie “ProjectC” defined in the ProjectB.json file and ProjectC use packages.config to manage the nuge package. There must be some restrictions to on the conversion of information between project.json file and packages.config. So when restore the dependencie “ProjectC” base on the ProjectA.json file will get that error.

To resolve this issue, you can add the CProject as reference for AProject directly.

Upvotes: 1

Tseng
Tseng

Reputation: 64121

First, your question is not related to .NET Core at all, as your xproj files do still target net46 and not netstandard1.3 (or lower).

If your only issue is that you can't reference Project C, then you need to package ProjectC into a nuget package, setup a nuget source and add it to your NuGet.Config (http://www.visualstudio.com/en-us/docs/package/nuget/consume).

Or use Visual Studio 2017, which allows you to directly reference a 4.x *.dll inside the csproj (xproj and project.json being deprecated from now on).

Upvotes: 0

Related Questions