Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: nugets from unity packages #623

Open
Orcolom opened this issue Feb 19, 2024 · 1 comment
Open

Question: nugets from unity packages #623

Orcolom opened this issue Feb 19, 2024 · 1 comment

Comments

@Orcolom
Copy link

Orcolom commented Feb 19, 2024

Description

Is there a way to support getting nugets defined in a unity package?
The idea would be that we have a central package that includes NugetForUnity and other packages would include nugets if they needed it.

@JoC0de
Copy link
Collaborator

JoC0de commented Feb 19, 2024

Hi @Orcolom,
thanks for the question.
The easiest way of achieving this is by simply adding a initialization script to your package.

[InitializeOnLoad]
public static class RestorNuGetPackages
{
  static RestorNuGetPackages()
  {
      if (EditorApplication.isPlayingOrWillChangePlaymode || SessionState.GetBool("NuGetPackagesRestored", false))
      {
          return;
      }

      SessionState.SetBool("NuGetPackagesRestored", true);
      RestoreSharedNuGetPackages();
  }

  [MenuItem("Custom/Restore Shared Packages")]
  public static void RestoreSharedNuGetPackages()
  {
    ....
  }
}

I'am not sure how we can integrate a feature that allows this using some sort of configuration. I can only imagine this two options:

  1. I mean one option would be to add a AdditionalPackageConfigFiles configuration value so you add the path to the packages.config of the shared package to the Nuget.config of the consumer project. But this needs configuration in the consumer project so it is no simple setup. Also the path to the packages.config need to be fixed.
  2. Add a Asset importer that triggers the nuget package restore when a packages.config asset is imported. I am not sure if this will be triggered at the correct time. Probably it will also trigger relatively often.

One additional problem that all of this approaches have is the way unity reloads assemblies / assets. So if we have a script that requires a NuGet package in the same assembly as the script that triggers the restore of the NuGet package Unity will not execute the package restore as it has compiler errors. I never tested if e.g. a packages.config file is imported even if the scripts of the containing assembly having compiler errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants