Search Unity

Custom dependencies in package.json

Discussion in 'Package Manager' started by ShawnFeatherly, Aug 15, 2018.

  1. ShawnFeatherly


    Feb 22, 2013
    What's the right way to add a dependency in a custom packages package.json to another custom package?

    I created 2 test packages that physically live in my packages folder. Resulting in the following folder structure.
    Code (csharp):
    1. - TestPackageManager
    2.   |- Assets
    3.   |- Packages
    4.      |- com.test.dependency
    5.      |- com.test.depender
    The first one, com.test.dependency, is the highest up the dependency chain. It includes Animal.cs.
    Code (CSharp):
    1.     public class Animal
    2.     {
    3.         public string Eat() { return "Stomach full"; }
    4.     }
    and its package.json is
    Code (JavaScript):
    1.     {
    2.     "name": "com.test.dependency",
    3.     "displayName": "Dependency",
    4.     "version": "0.0.1",
    5.     "unity": "2018.2",
    6.     "description": "Base project for another package to depend on",
    7.     "dependencies": { }
    8.     }
    I want the second package, com.test.depender, to be able to access it. It accesses it with Dog.cs
    Code (CSharp):
    1.     public class Dog : Animal { }
    and its package.json is
    Code (JavaScript):
    1.     {
    2.     "name": "com.test.depender",
    3.     "displayName": "Depender",
    4.     "version": "0.0.1",
    5.     "unity": "2018.2",
    6.     "description": "Tests dependency on another package",
    7.     "dependencies":
    8.       {
    9.         "com.test.dependency": "file:../com.test.dependency"
    10.       }
    11.     }
    This resulted in the error: .../TestPackageManager/Packages/com.test.depender/Dog.cs(1,20): error CS0246: The type or namespace name `Animal' could not be found. Are you missing an assembly reference?

    That would of been the preferred method of working. I thought maybe since the both packages were physically in the packages folder they might become part of the registry, so I also tried changing
    "com.test.dependency": "file:../com.test.dependency"
    "com.test.dependency": "0.0.1"

    Which resulted in the same error.

    Is there a way to get a custom package to have a dependency on another custom package to work?
  2. okcompute_unity


    Unity Technologies

    Jan 16, 2017
    Hi @ShawFeatherly,

    Please note that we are not currently explicitly exposing documentation about creating custom package nor giving support. This is not ready yet. There are still some quirks to be nailed before we let everyone build up their own packages and support this. Once we do, the user manual will be updated to explain throughly how to create custom packages and how to setup dependencies. Expect this feature to be enabled in a 2019.x release.

    That said, two things:

    1) local package (
    ) dependencies are not supported in packages, only in the project manifest (
    ). So, in the
    section of the depender package, you should have this:

    Code (CSharp):
    1. "dependencies":
    2.       {
    3.         "com.test.dependency": "0.0.1"
    4.       }
    5.     }
    2) The build error you get is caused by a wrong/missing assembly dependencies configuration. You should have an assembly definition file within both of the packages. The depender assembly should refer to the dependency assembly. See for more details.

    I'll be able to give more details soon :)


  3. ShawnFeatherly


    Feb 22, 2013
    Adding the assembly definitions as you described did the trick all by itself! Though, seems like a good idea to keep the package.json of com.test.Depender as you described just to keep it documented.

    Keeping the packages physically inside the packages folder will work until you're able to give more details. Seems like it will (probably?) make it easy to port to the right way of doing things when the time comes.

    @okcompute_unity , Thanks for the help!