I’m working on a project that is hosted on the company’s DevOps; since most project share the same basic functionalities, I’ve created a git submodule that gets imported into every project. However, I’m looking to migrate this to Unity’s package manager, so that it is easier to manage.
I’ve created a project as explained in this video, but whenever I try to import the package by adding the git url I get this error:
The error is pretty clear: Package name is invalid
Apparently you entered a full URL in there including “https://”
use something like: com.azure.whatever-the-package-name-is
if in doubt have a look at some other package.json to see what is expected
Package name is already following conventions, it’s not that. I’ve tried to upload the package to github and it is downloaded fine from there; it’s just Azure DevOps that has issues.
In the end I managed to do it…but via SSH. I’m going to write the whole procedure for all the people that are as ignorant as me in this matter;
Making the package is the easy part, and explained fully in the video in the first post I made;
Next step is generating SSH keys.
Open up shell or Powershell and run:
ssh-keygen
It will prompt you for a location where to save private and public keys; default name is id_rsa. Don’t change it, just press Enter. IMPORTANT keygen process will prompt you for a password. DO NOT insert the password, otherwise Unity won’t be able to logon later.
When all is done you will have generated two files*:*
id_rsa
id_rsa.pub
At the following path:
C:\Users\<your-user-name>\.ssh
Next, open up DevOps and go to the “Clone” tab in your Repo. Select “SSH” and then “Manage SSH Keys”
Click on “New Key” and in the Public Key Data field copy the contents of the id_rsa.pub you’ve generated earlier.
Save, and now go to Unity.
Take the SSH clone link you’ve copied earlier, and just add it to UPM as url:
I think the initial problem was that you’re passing a Git URL that does not “look” like one, so the Package Manager does not recognize it as such. URLs are recognized as Git URLs if they match one of the following criteria:
the path end with “.git” (IIRC Git repo URLs on Azure DevOps cannot end with .git)
the protocol is “git” (this is not frequently used) or is prefixed with “git+” (e.g. “git+https”, “git+ssh”)
the SCP-like short form of SSH URLs is used (e.g. <url>@<repo>:<path>)
In your case, since you are trying to use https and (AFAIK) cannot add the .git suffix, you should be able to get this to work by adding the “git+” prefix to the protocol. (This is a Unity Package Manager extension; that prefix is not passed to Git.)
EDIT:
Forget I said anything, the docs clearly state what I’m trying to do isn’t possible and I’m blind. From the docs (that I even linked below…):
Note: You can’t specify Git dependencies in a package.json file because the Package Manager doesn’t support Git dependencies between packages. It supports Git dependencies only for projects, so you can declare Git dependencies only in the project’s manifest.json file.
Sidenote: why isn’t this possible? Weird imo… That should have been a feature.
Original, now irrelevant, post:
I have a kind of similar issue. I have a custom package that I’ve added in a similar fashion as you pointed out, with the git+ prefix, hosted on AzDO. I want my package to have dependencies, also hosted on AzDO, however these won’t work. I think it’s because I’m targeting a specific branch. Is this a known issue, or am I doing something wrong? I’m referring to the docs. In the main package’s package.json, I have the dependencies set up like this:
[Package Manager Window] Error adding package: git+https://<companyname>@dev.azure.com/<companyname>/<projectname>/_git/<reponame>.
Unable to add package [git+https://<companyname>@dev.azure.com/<companyname>/<projectname>/_git/<reponame>]:
Package com.<companyname>.<productname>.<main-package>@git+https://<companyname>@dev.azure.com/<companyname>/<projectname>/_git/<reponame> has invalid dependencies or related test packages:
com.<companyname>.<productname>.util (dependency): Version 'git+https://<companyname>@dev.azure.com/<companyname>/<projectname>/_git/Util#<branch-name>' is invalid. Expected a 'SemVer' compatible value.
UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
Both dependencies get the same error, complaining about an invalid version. Worth noting is that if I add the dependencies as regular packages via the UPM using git URL (with a target <#branch-name>), they work fine. Only as dependencies do they fail.