Search code examples
.netvisual-studionugetproject.json

How to prevent proliferation of development dependencies with project.json floating versions?


I have a test utilities project (call it Utilities.Test) that specifies a nuget package as development dependency in its project.json file:

{
  "dependencies": {
    "devdep": {
        "version": "*",
        "type": "build"
    }
  },
  "frameworks": {
    "net45": {}
  },
  "supports": {},
  "runtimes": {
    "win": {}
  }
}

I package Utilities.Test as a nuget package and attempt to consume it in a test application (call it MyProject.Test), specifying the version as a floating value in the MyProject.Test project.json file:

{
  "dependencies": {
    "utilities.test": {
            "version": "*",
            "type": "build"
        }
  },
  "frameworks": {
    "net45": {}
  },
  "runtimes": {
    "win": {}
  }
}

When I do this, I get the following compilation error: "Unable to resolve devdep (>= x.x.x) for .NETFramework, Version=4.5". I've found two ways to resolve the issue:

  • Include devdep as a reference (with floating version) in the MyProject.Test project.json file as well.
  • Specify a concrete version number for Utilities.Test in the MyProject.Test project.json file.

Neither of these solutions is acceptable. I thought the whole point of specifying a package as a development dependency was to prevent it from being captured as an install dependency. How do I prevent devdep from being proliferated as a dependency when using floating versions?


Solution

  • I solved this by adding <developmentDependency>true</developmentDependency> to the nuspec file for Utilities.Test. This was already specified in the .nuspec file for devdep, so I'm unclear why that would be insufficient to prevent its proliferation. Also totally unclear now what the purpose of the "type": "build" tags in the project.json are for - would welcome any insight on these two questions.