Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

[Solved] Precompiled dlls in a package ignore define constraints

Discussion in 'Package Manager' started by DeepShade, Nov 9, 2019.

  1. DeepShade

    DeepShade

    Joined:
    Apr 10, 2018
    Posts:
    2
    Hi, in a nutshell I have the following folder structure
    Code (CSharp):
    1. <root>
    2.   ├── package.json
    3.   ├── Scripts
    4.   │   ├── SomeAssemblyDefinition.asmdef
    5.   │   └── SomeBehavior.cs
    6.   ├── Debug
    7.   │   └── MyLib.dll
    8.   └── Release
    9.       └── MyLib.dll
    - 'MyLib.dll' is a managed dll
    - The define constraint 'DEBUG' was set for the version in the folder 'Debug'
    - The define constraint '!DEBUG' was set for the version in the folder 'Release'
    - 'MyLib.dll' was added to the 'Assembly Refernces' array in 'SomeAssemblyDefinition.asmdef'
    - 'SomeBehavior.cs' uses some code of 'MyLib.dll'

    Note that everthing is working perfectly when all these files are inside the asset folder in my project. But when I push them to git and load them as package in another unity project, I get compile errors in 'SomeBehavior.cs' that the namespaces of 'MyLib.dll' are missing.

    The problem seems related to the import of the dll. To my suprise I noticed, when browsing through the imported package in the unity project view, that the type of the dll was switched to 'native' and that the define constraints property was gone (I assume native dlls cannot have define constraints?).
    Is this a bug or a missing feature or am I missing something else? Or is there even a better way to switch between different dlls in a package using define constraints?

    Btw. I'm using Unity 2019.3.0b10

    Thanks!
     
  2. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    520
    if a managed DLL is seen as native, it seems a bug (report it with https://unity3d.com/unity/qa/bug-reporting)
    the fact that native dlls cannot have define constraints is annoying, but probably related to the fact that you can't unload them without restarting Unity (you can report this too, but I assume it will be closed as By Design or something)
     
  3. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    140
    Had you not mentioned it, I wouldn't have noticed. I'm having issues with a package that gets deployed through Git URL. I thought at first it was due to the dll inside the package being marked for LFS management( I have another package which fails to retrieve some LFS managed pngs). So now I'm not sure. It could be either of those, or even worse, both.

    UPDATE: It's probably the LFS thing. I checked the dll in question inside the PackageCache folder for my package and it was 1KB when it's supposed to be around 500+KB. On the other hand, the pdb which is not marked(missed it) as LFS managed, seems to be correct in size. So for some reason the 1KB dll locally(perhaps the LFS pointer which does get fetched anyway) is then seen as native plugin. After replacing it with the correct dll, it was properly tagged as Managed and the errors went away.
     
    Last edited: Nov 11, 2019
  4. DeepShade

    DeepShade

    Joined:
    Apr 10, 2018
    Posts:
    2
    Wow, thank you very much. It has clearly something to do with git LFS. That really did not come into my mind. My dll is also only 1KB and when I open it in a text editor it shows:

    Code (CSharp):
    1. version https://git-lfs.github.com/spec/v1
    2. oid sha256:56b458d43f191a3ca0610b237ba703e7a5fc4269e605b90c916b596bf8bef1b6
    3. size 68608
    I disabled git LFS support for dlls in my package repository and I the dll is downloaded as expected. Nonetheless I thing it should be explicitly documented that LFS is not supported.
    Changing the 'Scripting Define Symbols' property in the 'Project Settings/Player' also changes the dll usage as indented, but only after restarting the editor. I think this is something to keep in mind.
     
  5. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    140
    LFS is supposed to be supported. I think this is just a bug. I've already reported it.