-
Notifications
You must be signed in to change notification settings - Fork 132
Embed link.xml in UPM package
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:
-
Add a section to your
README.mdtelling your users to create alink.xmlfile themselves in theirAssets/directory and add given content you specify. -
Embed your
link.xmlinside a precompiled assembly inside your package. -
Add your
link.xmlinside a directory namedRuntimeinside your package, and add acsc.rspfile to tell Unity to load it. (As mentioned by mike-voorhees) -
Generating a dynamic
link.xmlat build-time usingIUnityLinkerProcessor.GenerateAdditionalLinkXmlFilewhich seems to be supported from 2019.3 and later, according to the docs.
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
-
Create a .NET project, if you don't have one already. (Can be C#, F#, VB, whatever, as long as it has a
.*projfile) -
Add your
link.xmlfile to your project. Recommended to place it atResources/link.xml. -
Add the following to your
.*projfile (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 fileMyAssemblyName.xml, without<LogicalName>that embedded resource will then have the nameMyAssemblyName.MyAssemblyName.xml, which Unity will then not find. -
Replace
MyAssemblyNamewith the name of your assembly. -
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
new! Unity's package is now officially ready for public use: Install official UPM package
This package is licensed under The MIT License (MIT)
Copyright © 2019 Kalle Jillheden (jilleJr)
https://github.com/jilleJr/Newtonsoft.Json
See full copyrights in LICENSE.md inside repository
About- Home
-
Install Newtonsoft.Json
Deprecated:
-
Install converters for Unity