Reputation: 16845
I am using the latest version of Unity: 2019.3.14f1
.
In my project, I need to reference an external DLL. Following the procedure suggested in the manual, I have basically added the DLL as part of my assets. Unity automatically updates the C# project references to include that DLL, so everything works fine in the end.
However, now I need to include that DLL as part of my changes in my repository. So I need to commit it.
myproj
|--Scenes/
|--Assets/
|--MyAssembly.dll
But that is not really the best thing to do. Is there a way I can avoid this? Can Unity interface with a package manager such as NuGet or NPM? Visual Studio allows the use of NuGet packages, is there a way to tell Unity to create a C# project that references a specific sets of NuGet packages?
Upvotes: 4
Views: 8791
Reputation: 90659
Can Unity interface with a package manager such as NuGet or NPM?
Yes! That is exactly what Unity's Package Manager is used for.
Basically when you create your project you will find the automatically generated
YOURPROJECT/Packages/manifest.json
where you find the projects dependencies like e.g.
"com.unity.modules.physics": "1.0.0"
which reference to their NPM servers.
The linked API for the Package Manager is of course way more detailed and better explained so it's worth to read entirely through it even if you don't work with your custom packages. It helps a lot to understand in general how the PackageManager works and why there are sometimes so many errors with it when upgrading between version ^^
But in short: You can also use this to host and add your own Custom Packages as a dependency!
There are two forms of packages:
→ Is placed in YOURPROJECT/Packages/YOURPACKAGE
→ Can be anywhere on either your local drive or even an URL in the internet (to a Git repository)
You case sounds like you would want to go for the latter. Packages have to fulfill certain rules so make sure to read them up following the given links ;)
Then you follow these steps from the docs
Follow these instructions if you want to create a custom package outside your Project folder:
Using your computer’s file manager (for example the Windows File Explorer or the macOS Finder), create a folder for your package.
You can also use an existing location if you’ve already created some content for your package.
Make sure the layout of your folder structure follows the package layout convention for Unity packages. For example, if you have Editor and Runtime libraries, make sure they are stored under the Editor and Runtime folders.
Open your preferred text editor and create a JSON file called
package.json
.Save it under the package root folder.
Fill out all required and mandatory fields in the package manifest (
package.json
) file.In Unity, create a new Project or open an existing Project.
Open the Packages window and follow the instructions for installing a local package, using the
package.json
file you just created.The new package appears in the Package Manager window and in the Project window, where you can view and modify the package contents. If you select the
package.json
file in the Project window, you can also modify its contents directly in the Inspector window.
So your dependency could then e.g. look like
"dependencies": {
...
"my_local_package": "file:C:/Users/johndoe/Packages/my_local_package"
}
or also using a relative path
"dependencies": {
...
"my_local_package": "file:../Packages/my_local_package"
}
or even be an external URL to a git repo
"dependencies": {
...
"my_local_package": "https://someGitHost/projectrepo.git"
}
I also found this tutorial which explained it quite good step-by-step.
Upvotes: 5