Search Unity

Custom dependencies in package.json

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

  1. ShawnFeatherly

    ShawnFeatherly

    Joined:
    Feb 22, 2013
    Posts:
    57
    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"
    to
    "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

    okcompute_unity

    Unity Technologies

    Joined:
    Jan 16, 2017
    Posts:
    756
    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 (
    file:
    ) dependencies are not supported in packages, only in the project manifest (
    manifest.json
    ). So, in the
    dependencies
    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 https://docs.unity3d.com/2017.3/Documentation/Manual/ScriptCompilationAssemblyDefinitionFiles.html for more details.

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

    Regards,

    Pascal
     
    TildeAsterisk likes this.
  3. ShawnFeatherly

    ShawnFeatherly

    Joined:
    Feb 22, 2013
    Posts:
    57
    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!
     
  4. Christopher-Anderson-GISP

    Christopher-Anderson-GISP

    Joined:
    Mar 5, 2015
    Posts:
    19
    i'm using 2020.3 and attempting to create a custom package. i finally figured out how to add json.net using "com.unity.nuget.newtonsoft-json"(v 2.0.0) but how would you add a dependency to one purchased from the asset store. one of the assets i have a dependency on is BestHTTP/2.
     
  5. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    From what I understand, you want your UPM package to depend on an Asset Store "package". That's not currently supported.
     
  6. HarisKap

    HarisKap

    Joined:
    Dec 10, 2012
    Posts:
    20
    Hello, I am trying to create a custom package that have depedencies on other custom packages, how you can do that? if I put the assembly reference it ends up being empty on the other client. Do I need to move those custom packages under my package folder?
     
  7. stamatian

    stamatian

    Joined:
    Jul 13, 2018
    Posts:
    36
    Hi I'm creating a Unity package following this guide: https://docs.unity3d.com/Manual/cus-layout.html
    The package will contain common UI components and I will use DOTween for animations so I want my package to be dependent on it... I saw there is a package on OPEN UPM: https://openupm.com/packages/com.demigiant.dotween/
    I added the dependency inside package.json but it's not working:
    upload_2022-5-25_22-42-24.png
    Is it supported? How can I achieve this?
     
    Gasimo likes this.