NuGetForUnity

repository·master·Indexed 26 days ago

https://github.com/glitchenzo/nugetforunity

A custom NuGet client for the Unity Editor that allows developers to manage NuGet packages, handle dependencies, and publish packages using .nuspec files. It includes a management interface for searching, installing, and updating packages, as well as a CLI tool (NuGetForUnity.Cli) for package restoration in CI/CD environments. The tool supports custom NuGet servers, plugin extensibility via the INugetPlugin interface, and configurable directory structures for NuGet.config and packages.config.

Tokens
3.9K
Snippets
11
Records
22
Agent score
39%

What's inside NuGetForUnity

  1. Manage NuGet Packages in Unity

    master

    To open the NuGet management interface, navigate to NuGet → Manage NuGet Packages in the Unity menu.

    Online Tab

    Search and install packages from the NuGet server.

    • Show Prerelease: Toggle to include alpha, beta, or RC versions.
    • Search: Filter displayed packages.
    • Install: Click to install the version selected in the dropdown.
    • Select all from clipboard: Add multiple packageIds (separated by new lines or commas) to the selection list.

    Installed Tab

    View currently installed packages.

    • Installed packages: Direct project dependencies.
    • Implicitly installed packages: Transitive dependencies.
    • Uninstall: Removes the package and its unused dependencies.
    • Add as explicit: Moves an implicit dependency to the explicit list so it isn't automatically uninstalled.

    Updates Tab

    Manage package versions.

    • Show Downgrades: If checked, shows available lower versions. If unchecked, shows only higher versions.
    • Update/Downgrade: Click to uninstall the current version and install the selected version.
  2. Enable Verbose Logging for debugging

    master

    To see detailed process logs in the Unity console for debugging, you can enable verbose logging in two ways:

    1. Check the Use Verbose Logging checkbox in the NuGet For Unity settings window.
    2. Add <add key="verbose" value="true" /> to the <config> element in your NuGet.config file.
  3. Restore NuGet Packages after a Fresh Checkout

    master

    When cloning a project, you may see compiler errors because Unity attempts to compile scripts before NuGet packages are restored. Use one of these two methods:

    Restore all packages using the NuGetForUnity CLI tool before opening the project in Unity. This ensures all dependencies in packages.config are present before the first compilation.

    If you see compiler errors on startup:

    1. Select Ignore (not Safe Mode) on the Unity compile error popup.
    2. NuGetForUnity will automatically restore packages in the background.
    3. Once complete, Unity will recompile and errors should resolve.

    Alternatively, trigger a manual restore via NuGet → Restore Packages.

  4. Restore NuGet packages manually

    master

    The Restore operation automatically runs when the project is opened or code is recompiled. To trigger it manually, select NuGet → Restore Packages from the Unity menu.

    Note: Depending on the number of packages, restoration may take a long time. If Unity appears unresponsive, wait several minutes before force-closing the process.

  5. Restore NuGet packages via CLI (for CI/CD)

    master

    For automated build environments, use the NuGetForUnity.Cli .NET tool to restore packages without opening the Unity Editor.

    Installation

    Global Tool:

    dotnet tool install --global NuGetForUnity.Cli

    Local Tool (Project-wide):

    dotnet new tool-manifest
    dotnet tool install NuGetForUnity.Cli

    (Remember to commit .config/dotnet-tools.json to your repository).

    Usage

    To restore packages for a specific Unity project:

    dotnet nugetforunity restore <PROJECT_PATH>

    If installed as a global tool, you can omit the dotnet prefix: nugetforunity restore <PROJECT_PATH>.

    dotnet nugetforunity restore <PROJECT_PATH>
  6. Install NuGetForUnity via manifest.json (Unity 2019.2 or earlier)

    master

    For older Unity versions, manually edit the manifest.json file:

    1. Close the Unity Editor.
    2. Open Packages/manifest.json in a text editor.
    3. Insert the following line inside the dependencies object:
    "com.glitchenzo.nugetforunity": "https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity",
    1. Reopen the Unity project.
  7. Install NuGetForUnity via Git URL (Unity 2019.3+)

    master

    For Unity 2019.3 or newer, use the Unity Package Manager:

    1. Open Window | Package Manager.
    2. Click the + button and select Add package from git URL....
    3. Enter the following URL:
    https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity

    To install a specific version, append #v{version} to the URL (e.g., #v2.0.0).

  8. Create a NuGetForUnity Plugin

    master

    To develop a plugin for NuGetForUnity, follow these requirements:

    1. Naming Convention: Your plugin project name must follow the pattern <PluginName>.NugetForUnityPlugin. The plugin loader specifically searches for DLLs containing NugetForUnityPlugin in their name.
    2. Target Framework:
      • For Unity versions older than 2021.3: Use a .netstandard2.0 C# library project.
      • For Unity 2021.3 or newer: Use a .netstandard2.1 C# library project.
    3. Dependencies:
      • Add a reference to the NuGetForUnity.PluginAPI NuGet package to access required interfaces.
      • Optionally add references to UnityEngine.dll and UnityEditor.dll from your Unity installation if your plugin interacts with the engine or editor.
    4. Implementation: Create a class that implements the INugetPlugin interface. In the Register method, use the provided INugetPluginRegistry to register your custom handlers.
  9. Create NuGet packages from within Unity

    master

    You can package your own code into .nupkg files directly from the Unity Editor:

    1. Right-click in the Project window and select NuGet → Create Nuspec File.
    2. Edit the .nuspec file to include your package ID, Version, Author, Description, and any required dependencies.
    3. Select the .nuspec file and click the Pack button to generate the .nupkg file (saved to your local NuGet cache).
    4. Click the Push button to upload the package to your server (requires a valid API Key if configured).
  10. Configure NuGet directory structure

    master

    NuGetForUnity supports two directory structures for storing NuGet.config, packages.config, and downloaded *.dll files. You can switch between these in the NuGet For Unity settings UI.

    Custom within Assets

    • NuGet.config is placed in <Unity Project Location>/Assets.
    • The location of packages.config and installed packages is controlled by the repositoryPath variable in NuGet.config.
    • By default, repositoryPath is Assets/Packages.
    • Tip: You should likely add your Packages folder to .gitignore to avoid versioning large binaries.

    In Packages folder

    • All configuration and packages are stored in <Unity Project Location>/Packages/nuget-packages.
    • This keeps the Assets directory clean.
    • In this mode, the path to packages.config and the installed packages directory cannot be changed.