Hi I’m trying to find a solution to exlcude packages at build time. I’m creating a pipeline to build a project using URP or HDRP and I need to exclude the unused render pipeline at build time (both of those packages are embedded).
For now, I’m moving the package directory out of the project and force a Resolve before executing a build launch. But I have some issues at compilation and my build crashes.
I’ve tried to manually remove the package before and build after and everything works perfectly. I used the same process, I’ve just executed separately the package exclude and the build (before I was executing both in the same method).
Is there a way to get a callback when packages are resolved or is there another way to exclude embedded packages at build time without this issue ?
I’m not aware of any build-time hooks that would work for what you’re asking, but normally, when you build the player, unused managed code will be stripped by the UnityLinker step, so I think manually removing the package and re-adding it after the build is done should not be necessary. Have you verified whether this is happening or not? You could inspect the built player’s assemblies and compare your technique with what gets built if you just let the build pipeline apply the stripping logic.
Alternatively, if both packages are embedded, that means you can modify them, so you could set your own scripting symbols when switching to one of the other (e.g. MYPROJECT_USE_URP) and add “defineConstraints” on all assembly references of each package so the code gets automatically excluded by the compiler. See Unity - Manual: Assembly Definition properties