Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Embed link.xml in UPM package

Kalle Jillheden edited this page Jun 18, 2021 · 3 revisions

As mentioned in Where to place the link.xml Unity does not look for link.xml files in referenced UPM packages.

You have some options:

  1. Add a section to your README.md telling your users to create a link.xml file themselves in their Assets/ directory and add given content you specify.

  2. Embed your link.xml inside a precompiled assembly inside your package.

  3. Add your link.xml inside a directory named Runtime inside your package, and add a csc.rsp file to tell Unity to load it. (As mentioned by mike-voorhees)

  4. Generating a dynamic link.xml at build-time using IUnityLinkerProcessor.GenerateAdditionalLinkXmlFile which seems to be supported from 2019.3 and later, according to the docs. A rough example of this can be found over at the Unity forums by bobbaluba.

We will be going through option 2.

An extensive list of alternatives can be found over here: https://forum.unity.com/threads/the-current-state-of-link-xml-in-packages.995848/#post-6545491

Embedded resource

  1. Create a .NET project, if you don't have one already. (Can be C#, F#, VB, whatever, as long as it has a .*proj file)

  2. Add your link.xml file to your project. Recommended to place it at Resources/link.xml.

  3. Add the following to your .*proj file (ex: .csproj):

      <ItemGroup>
        <EmbeddedResource Include="Resources\link.xml">
          <LogicalName>MyAssemblyName.xml</LogicalName>
        </EmbeddedResource>
      </ItemGroup>

    The file must be an embedded resource, and if you omit the <LogicalName> property then the resource will get a generated name with the assembly name prefixed on the files name. Even if you name your file MyAssemblyName.xml, without <LogicalName> that embedded resource will then have the name MyAssemblyName.MyAssemblyName.xml, which Unity will then not find.

  4. Replace MyAssemblyName with the name of your assembly.

  5. Compile and include the DLL in your package. For most cases, you can precompile all your C# code you would anyway include into your package to get much faster compiling and loading for the user, at the cost of a little bigger package size.

The above solution is used in Newtonsoft.Json-for-Unity, as can be seen here: https://github.com/jilleJr/Newtonsoft.Json-for-Unity/blob/bfd8ab8/Src/Newtonsoft.Json/Resources/link.xml

Clone this wiki locally