Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A NuGet Package Manager for Unity

License

NotificationsYou must be signed in to change notification settings

GlitchEnzo/NuGetForUnity

Repository files navigation

openupmmain github action workflowMIT licenseGitHub Release

What is NuGetForUnity?

NuGetForUnity is a NuGet client built from scratch to run inside the Unity Editor. NuGet is a package management system which makes it easy to create packages that are distributed on a server and consumed by users. NuGet supportssemantic versioning for packages as well as dependencies on other packages.

You can learn more about NuGet here:nuget.org

NuGetForUnity provides a visual editor window to see available packages on the server, see installed packages, and see available package updates. A visual interface is also provided to create and edit.nuspec files in order to define and publish your own NuGet packages from within Unity.

Online Packages Tap

How do I install NuGetForUnity?

Install via OpenUPMThe package is available on theopenupm registry. So you can install it via openupm-cli or manually using a scoped registry see documentation atopenupm.
openupm add com.github-glitchenzo.nugetforunity
Install as GIT dependency via Package Manager

Unity 2019.3 or newer

  1. Open Package Manager window (Window | Package Manager)
  2. Click+ button on the upper-left of a window, and select "Add package from git URL..."
  3. Enter the following URL and clickAdd button
https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity

NOTE: To install a concrete version you can specify the version by prepending #v{version} e.g.#v2.0.0. For more seeUnity UPM Documentation.

Unity 2019.2 or earlier

  1. Close Unity Editor

  2. Open Packages/manifest.json by any Text editor

  3. Insert the following line after"dependencies": {, and save the file.

    "com.glitchenzo.nugetforunity":"https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity",
  4. Reopen Unity project in Unity Editor

Install via .unitypackage file

Install the provided Unity package into your Unity project. Locatedhere.

Download the*.unitypackage file. Right-click on it in File Explorer and choose "Open in Unity."

How do I use NuGetForUnity?

To launch, selectNuGet → Manage NuGet Packages

Menu Items

After several seconds (it can take some time to query the server for packages), you should see a window like this:

Online Packages Tap

TheOnline tab shows the packages available on the NuGet server.

EnableShow Prerelease to list prerelease versions of packages (alpha, beta, release candidate, etc).DisableShow Prerelease to only show stable releases.

Type a search term in theSearch box to filter what is displayed.

Press theRefresh button to refresh the window with the latest query settings. (Useful after pushing a new package to the server and wanting to see it without closing and reopening the window.)

The name of the package, publisher, number of downloads and description are displayed.

Click theView License after expandingDetails to open the license in a web browser.

Click theInstall to install the package version specified in the dropdown list next to the button.Note: If the package is already installed, the currently installed version will be displayed in the upper right corner instead.If theInstall button is disabled, it means the package is already imported by Unity.

You can also select multiple packages for installation and install them all at once.

In addition to manual selection you can also copy a list of packageIds that you need to install, separated by new line or comma, and simply click the "Select all from clipboard" button at the top right to add them all to the selection.Note that if the package is already installed or available in Unity it will not show up in the selected list.

TheInstalled tabs shows the packages already installed in the current Unity project.

Installed Packages Tap

TheInstalled packages part of the list shows packages directly installed as project dependencies.

TheImplicitly installed packages part shows packages that are installed as transitive dependencies.

Click theUninstall button to uninstall the package.When uninstalling anexplicitly installed package, all of its dependencies that are not a dependency of any other package or the project itself will also be uninstalled.

IfAdd as explicit is clicked on animplicitly installed package, it will be moved to the first part of the list and willnot be automatically uninstalled in a scenario described above.

TheUpdates tab shows the packages currently installed, and offers options to update to available higher versions or downgrade to lower versions.

IfShow Downgrades is not checked, all packages that have available versions that are higher than the currently installed version will be shown, and there will be a dropdown list next toUpdate button with available versions for update.

Updates Packages Tab Update

TheUpdate All button is shown only ifShow Downgrades is not checked, and it will update all packages with versions currently selected in their respective dropdown lists.

Similarly, ifShow Downgrades is checked, all packages that have available versions that are lower than the currently installed version will be shown, and there will be a dropdown list next toDowngrade button with available versions for downgrade.

Updates Packages Tab Downgrades

By default, the selected version in the dropdown list is thehighest newer orhighest lower version, depending on theShow Downgrades checkbox.

Click theUpdate (orDowngrade) button to uninstall the current package and install the new package.

How does NuGetForUnity work?

NuGetForUnity loads theNuGet.config file in the Unity project (automatically created if there isn't already one) in order to determine the server it should pull packages down from and push packages up to. By default, this server is set to thenuget.org package source.

The default NuGet.config file:
<?xml version="1.0" encoding="utf-8" ?><configuration>    <packageSources>        <clear />        <addkey="nuget.org"value="https://api.nuget.org/v3/index.json" />    </packageSources>    <activePackageSource>        <addkey="All"value="(Aggregate source)" />    </activePackageSource>    <config>        <addkey="repositoryPath"value="./Packages" />    </config></configuration>

You can change this to any other NuGet server (such as NuGet.Server or ProGet - see below). TheNuGet → Restore Packages menu item is useful if you edited theNuGet.config file. See more information aboutNuGet.config files here:https://docs.nuget.org/consume/nuget-config-settings

Directory structure (placement of configuration files and installed packages)

NuGetForUnity supports two different folder structures for defining where the configuration filesNuGet.config,packages.config, and the downloaded*.dll files of the NuGet packages are stored. The placement can be changed in theNuGet For Unity settings UI.

Custom within Assets

TheNuGet.config file will be placed in<Unity Project Location>/Assets, and the placement of thepackages.config file and the installed packages can be changed using configuration variables inside theNuGet.config file. The path where NuGetForUnity installs packages, the local repository path, is defined in theNuGet.config file (repositoryPath). By default, this is set to theAssets/Packages folder. The configured path can either be a full path or a relative path based on the project's Assets folder. Note: You'll probably want your Packages folder to be ignored by your version control software to prevent NuGet packages from being versioned in your repository.

Example directory structure:
<Unity Project Location>├── Assets│   ├── NuGet.config│   ├── packages.config│   └── Packages│       └── Serilog.2.12.0│           ├── icon.png│           └── lib│               └── netstandard2.1│                   └── Serilog.dll

In Packages folder

All configuration files and the installed packages are placed inside<Unity Project Location>/Packages/nuget-packages. This way, theAssets directory will not contain any files. In this placement method, the path to thepackages.config file and the installed packages directory cannot be changed.

Example directory structure:
<Unity Project Location>├── Packages│   └── nuget-packages│       ├── NuGet.config│       ├── packages.config│       └── InstalledPackages│           └── Serilog.2.12.0│               ├── icon.png│               └── lib│                   └── netstandard2.1│                       └── Serilog.dll

Content ofpackages.config file

When a package is installed, thepackages.config file in the project is automatically updated with the specific package information, as well as all of the dependencies that are also installed. This allows for the packages to be restored from scratch at any point. TheRestore operation is automatically run every time the project is opened or the code is recompiled in the project. It can be run manually by selecting theNuGet → Restore Packages menu item.

Menu Items

Note: Depending on the size and number of packages you need to install, theRestore operation could take along time, so please be patient. If it appears the Unity isn't launching or responding, wait a few more minutes before attempting to kill the process.

Verbose Logging

If you are interested in the process NuGetForUnity follows or you are trying to debug an issue, you can force NuGetForUnity to use verbose logging to output an increased amount of data to the Unity console. Either check theUse Verbose Logging checkbox in theNuGet For Unity settings window or add the line<add key="verbose" value="true" /> to the<config> element in theNuGet.config file. You can disable verbose logging by either setting the value to false or completely deleting the line.

Caching

The.nupkg files downloaded from the NuGet server are cached locally in the current user's Application Data folder%localappdata%\NuGet\Cache (Windows:C:\Users\[username]\AppData\Local\NuGet\Cache, Mac/Linux:~/.local/share/NuGet/Cache). The cache location can be overwritten by setting theNuGetCachePath environment variable. Packages previously installed are installed via the cache folder instead of downloading it from the server again.

Advanced settings

Use custom NuGet server

The default configuration usesnuget.org but package sources hosted on other servers should also work. Some need some special settings. The setting can be either set using configuration UINuGet → Preferences or in theNuGet.config. Some examples:

Azure Artifacts / GitHub Packages

They require thesupportsPackageIdSearchFilter set tofalse e.g.:

<?xml version="1.0" encoding="utf-8" ?><configuration>    <packageSources>        <addkey="github"value="https://nuget.pkg.github.com/NAMESPACE/index.json"supportsPackageIdSearchFilter="false" />    </packageSources>    <packageSourceCredentials>        <github>            <addkey="userName"value="USERNAME" />            <addkey="clearTextPassword"value="TOKEN" />        </github>    </packageSourceCredentials>    ...</configuration>

JFrog Artifactory

RequiresprotocolVersion set to3 the other required settings likepackageDownloadUrlTemplateOverwrite should be automatically detected / configured.

<?xml version="1.0" encoding="utf-8" ?><configuration>    <packageSources>        <addkey="Artifactory"value="https://company.com/artifactory/api/nuget/v3/PROJECT"protocolVersion="3"packageDownloadUrlTemplateOverwrite="https://company.com/artifactory/api/nuget/v3/PROJECT/registration-semver2/Download/{0}/{1}"updateSearchBatchSize="1"        />    </packageSources>    <packageSourceCredentials>        <Artifactory>            <addkey="userName"value="USERNAME" />            <addkey="clearTextPassword"value="Password" />        </Artifactory>    </packageSourceCredentials></configuration>

Storing credentials outside of the projectNuGet.config file

When using a custom NuGet server that requires aUserName and aPassword, you probably wouldn't store it in theNuGet.config file that is stored in the Unity Project as it will be committed to source control. Therefore, we support loading thepackageSourceCredentials section from the system or user-specificnuget.config file. The storage location of the system or user-specificnuget.config files are documented atMicrosoft's NuGet Configuration (e.g., on Windows%AppData%\NuGet\NuGet.Config).

Disable automatic referencing of assemblies

To disable the automatic referencing of assemblies of a NuGet package you can set theautoReferenced attribute of a package inside thepackages.config tofalse.Currently this setting is not available from UI.

<?xml version="1.0" encoding="utf-8" ?><packages>    <packageid="Serilog"version="2.12.0"autoReferenced="false" /></packages>

When this setting is set tofalse the assemblies of the NuGet package are only referenced by Unity projects that explicitly list them inside there*.asmdef file.

How do I create my own NuGet packages from within Unity?

First, you'll need to create a.nuspec file that defines your package. In your Project window, right click where you want the.nuspec file to go and selectNuGet → Create Nuspec File.

Create Nuspec Menu

Select the new.nuspec file and you should see something like this:

Nuspec editor

Input the appropriate information for your package (ID, Version, Author, Description, etc). Be sure to include whatever dependencies are required by your package.

Press thePack button to pack your package into a.nupkg file that is saved in theC:\Users\[username]\AppData\Local\NuGet\Cache folder.

Press thePush button to push your package up to the server. Be sure to set the correct API Key that give you permission to push to the server (if you server is configured to use one).

How do I create my own NuGet server to host NuGet packages?

You can useNuGet.Server,NuGet Gallery,ProGet, etc to create your own NuGet server.

Note: NuGetForUnity doesn't use the official NuGet Client implementation form Microsoft, so authenticating against a third-party NuGet server is currently not supported for every case. If you ran into authentication issues please create a issue so we can try to implement it.

Alternatively, you can use a "local feed" which is just a folder on your hard-drive or a network share.Local NuGet feeds can have two different structures:

  • flat: <local feed path>/<package id>.<package version>.nupkg
  • hierarchical: <local feed path>/<package id>/<package version>/<package id>.<package version>.nupkg

Be sure to set the proper URL/path in theNuGet.config file and you should be good to go!

Read more information here:http://docs.nuget.org/create/hosting-your-own-nuget-feeds

Restoring NuGet Packages over the Command Line

For those with projects using automated build solutions likecontinuous integration, NuGetForUnity provides the ability to restore your NuGet packages directly from the command line without starting Unity. This is achieved using a separateNuGetForUnity.Cli NuGet package containing a.Net Tool.

Installation

  • System-wide as a global tool using:dotnet tool install --global NuGetForUnity.Cli.
  • Project / folder wide as a local tool using: A tool manifest (local tool installation context) can be created with:dotnet new tool-manifest. Than install NuGetForUnity.Cli using:dotnet tool install NuGetForUnity.Cli. Than add the tool manifest.config/dotnet-tools.json to your version control system.

For more information see.Net Tool Documentation.

Usage

Restore nuget packages of a single Unity Project:dotnet nugetforunity restore <PROJECT_PATH>. If installed as a global tool it can be called without thedotnet prefix:nugetforunity restore <PROJECT_PATH>.

Plugin support

NugetForUnity has plugin support. If you open the NugetForUnity section in Unity preferences it will list the plugins you have installed in your project and you can enable them from there.

Plugins are any dlls which contain NugetForUnityPlugin in their name and have a class inside them that implements theINugetPlugin interface. They can be placed anywhere inside the project (inside theAssets directory).

If you are interested in implementing a plugin read theplugin development documentation.

Common issues when installing NuGet packages

In the .Net ecosystem Unity is relatively special as it doesn't use the standard .Net runtime from Microsoft instead, it uses a fork of theMono runtime. For some platforms Unity even usesIL2CPP that compiles all C# code to C++ code. So Unity also uses a different build-system. This can lead to some issues with NuGet packages that heavily depend on the standard .Net build-system. NuGetForUnity tries to handle most of the changes needed to allow using NuGet packages inside Unity but it is not able to resolve all issues. This section contains some common issues and potential solutions.

Version Conflicts

If two NuGet packages depend on the same package but reference different versions of it, Unity shows an error like:

Assembly 'Assets/Packages/System.Diagnostics.EventLog.4.7.0/lib/netstandard2.0/System.Diagnostics.EventLog.dll' will not be loaded due to errors:System.Diagnostics.EventLog references strong named System.Security.Principal.Windows Assembly references: 4.1.1.0 Found in project: 4.1.3.0.Assembly Version Validation can be disabled in Player Settings "Assembly Version Validation"

As mentioned in the message this error can be suppressed by changing a setting. Just go to Edit -> Project Settings -> Player -> Scroll down and expand "Other Settings" than uncheck "Assembly Version Validation" under the "Configuration" section.

Screenshot of Player Settings

Missing System libraries

When targeting .Net Framework, the 'Api Compatibility Level' setting underEdit ->Project Settings ->Player ->Other Settings is set to .NET Framework, Unity doesn't include some System libraries by default. See alsoUnity documentation about system libraries andUnity documentation about .Net Profiles. Libraries that are not imported by default are e.g.System.Drawing,System.IO.Compression,System.IO.Compression.FileSystem andSystem.Net.Http. If you try to use one of this libraries you get an error like:

The type `HttpClient` is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

To import one of the System libraries and resolve the error you need to create acsc.rsp file with the content e.g. to importSystem.Net.Http

-r:System.Net.Http.dll

and place it inside the containing project that requires the library (e.g. theAssets folder). It can also be placed in a folder that contains a.asmdef to only add the reference to the sub-project. For example NuGetForUnity also uses acsc.rsp file seecsc.rsp.


[8]ページ先頭

©2009-2025 Movatter.jp