using NugetForUnity.Configuration; using UnityEditor; namespace NugetForUnity { /// /// Automatically restores NuGet packages when Unity opens the project. /// [InitializeOnLoad] public static class OnLoadNugetPackageRestorer { /// /// Initializes static members of the class. /// Static constructor used by Unity to initialize NuGet and restore packages defined in packages.config. /// static OnLoadNugetPackageRestorer() { if (SessionState.GetBool("NugetForUnity.FirstProjectOpen", false)) { return; } SessionState.SetBool("NugetForUnity.FirstProjectOpen", true); // if we are entering play-mode, don't do anything if (EditorApplication.isPlayingOrWillChangePlaymode) { return; } // Load the NuGet.config file ConfigurationManager.LoadNugetConfigFile(); // restore packages - this will be called EVERY time the project is loaded PackageRestorer.Restore(ConfigurationManager.NugetConfigFile.SlimRestore); } } }