Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

while custom package need a link.xml.

Discussion in 'Package Manager' started by wang37921, Aug 14, 2019.

  1. wang37921

    wang37921

    Joined:
    Aug 1, 2014
    Posts:
    81
    If a custom package need a link.xml, it support now? where put it?
    Unity will merge all the link.xml?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,401
    Unity does not support link.xml files in packages. You can find full details about managed code stripping and link.xml files in the Unity manual here: https://docs.unity3d.com/Manual/ManagedCodeStripping.html

    Can you elaborate on the need for a link.xml file in a package? Are you the author of a package that needs a link.xml file?
     
  3. wang37921

    wang37921

    Joined:
    Aug 1, 2014
    Posts:
    81
    Thanks,
    My custom package using a json framework, so i want convert the exist json to a upm.(more than one package need it.)
    the exist json framework just a dll, so i thought could i wrap it into a upm: https://github.com/mapotofu-fun/Json
    while i read the json framework, it says need a link.xml, so i post this thread.
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,401
    It looks like that JSON code normally requires the user put a link.xml file in their project. I think the same will be true of this library when it is shipped as a package then.
     
  5. wang37921

    wang37921

    Joined:
    Aug 1, 2014
    Posts:
    81
    hum... it's a solution..
    but i think keep self-integrity will be better. otherwise, i need keep the tips in README.
    maybe merge link.xml, gizmos...and other special folder and files is more intuition.
    personal option, if could be accept. it's very cool.
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,401
    I agree, the current situation is not great. We're still working out the best way to handle cases like this.
     
    EirikWahl likes this.
  7. z000z

    z000z

    Joined:
    Dec 31, 2014
    Posts:
    90
    @JoshPeterson has there been any updates on this, is there still no way to include a link.xml with a custom package?

    We're moving a bunch of our code to custom packages to better support re-use, which changes how il2cpp works (local code doesn't get stripped, but once you move it into a custom package it's subject to stripping) and it would be ideal if we could keep up with the stripping rules at the package level instead of figuring it all out at each end project.
     
    FabioMAG likes this.
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,401
    Unfortunately we don't have too much to say about this yet. I can offer two work arounds though.

    First, you can use the [Preserve] attribute in your source code to prevent the linker from removing any classes and methods you want to keep.

    Second, you can embed a link.xml as a resource in an assembly, and the linker will pick it up and use it as if it were a file in the project.
     
    EirikWahl likes this.
  9. z000z

    z000z

    Joined:
    Dec 31, 2014
    Posts:
    90
    Oh ok, that second option looks promising, if you have multiple assemblies with embedded link.xml is there any sort of merging that would happen or will it just pick one somewhat randomly?
     
  10. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,401
    All of the link.xml files will be merged, similar to the way multiple link.xml files can be used in the same Unity project in different directories.
     
  11. mnavarro

    mnavarro

    Joined:
    Dec 29, 2011
    Posts:
    1
    Hi Josh,
    We can embed our package link.xml to the package assembly or a project assembly ?
     
  12. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    4,401
    I'm unsure what you mean by the distinction between package assembly and project assembly. Can you clarify?
     
  13. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    254
    You could use the package samples workflow to allow users to import a pre-written sample link.xml file into their assets directory which copies from the original in your package. not ideal but could get you by for now.
     
  14. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    140
    Is it planned to add support for link.xml into packages?
     
  15. FabioMAG

    FabioMAG

    Joined:
    Oct 17, 2017
    Posts:
    8
    Google recently released Firebase via UPM and they are also facing the same issue: https://github.com/firebase/quickstart-unity/issues/623

    This will become more and more frequent as more people and companies move towards UPM to manage private packages, so ideally we'd have some solution to this that gives control to who is publishing the package to manage it directly from the package.

    I understand we can use the [Preserve] attribute but this is not always an option (e.g. adding a third-party dependency that uses dlls, such as Json .NET for Unity 2.0.1, which will cause code stripping issues without its link.xml file). Another potential workaround is to copy the link.xml file from the package folder into the Assets folder, before building (Pre Processor) but this is not ideal.
     
  16. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    140
    Thanks for the suggestion! Seems like the current solution is to write a preprocessor that goes through all the packages and copies (and ideally merges) all link.xml files it finds.

    We also had issues with JSON .Net and Firebase this week...
     
    Last edited: May 8, 2020
    FabioMAG likes this.
  17. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    140
    So I actually wrote an editor tool that extracts all link.xml files from packages, merges them and includes in the build.
    Place it in an Editor folder and it will do all the magic during build time.
    https://pastebin.com/m8i3xecr
     
unityunity