Open Orcolom opened 8 months ago
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:
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.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.
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.