Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for GitHub / Azure Artefacts #602

Merged
merged 5 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 64 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,19 @@ NuGetForUnity loads the _NuGet.config_ file in the Unity project (automatically

_The default NuGet.config file:_

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

Expand All @@ -152,10 +152,59 @@ Note: Depending on the size and number of packages you need to install, the `Res

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. Add the line `<add key="verbose" value="true" />` to the `<config>` element in the _NuGet.config_ file. You can disable verbose logging by either setting the value to false or completely deleting the line.

The _.nupkg_ files downloaded from the NuGet server are cached locally in the current user's Application Data folder `%localappdata%\NuGet\Cache` (`C:\Users\[username]\AppData\Local\NuGet\Cache`). The cache location can be overwrtten by setting the `NuGetCachePath` environment variable. Packages previously installed are installed via the cache folder instead of downloading it from the server again.
The _.nupkg_ files downloaded from the NuGet server are cached locally in the current user's Application Data folder `%localappdata%\NuGet\Cache` (`C:\Users\[username]\AppData\Local\NuGet\Cache`). The cache location can be overwritten by setting the `NuGetCachePath` 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 uses `nuget.org` but package sources hosted on other servers should also work. Some need some special settings. The setting can be either set using configuration UI **NuGet → Preferences** or in the `NuGet.config`. Some examples:

### Azure Artifacts / GitHub Packages

They require the `supportsPackageIdSearchFilter` set to `false` e.g.:

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

### JFrog Artifactory

Requires `protocolVersion` set to `3` the other required settings like `packageDownloadUrlTemplateOverwrite` should be automatically detected / configured.

```xml
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<packageSources>
<add
key="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>
<add key="userName" value="USERNAME" />
<add key="clearTextPassword" value="Password" />
</Artifactory>
</packageSourceCredentials>
</configuration>
```

## Disable automatic referencing of assemblies

To disable the automatic referencing of assemblies of a NuGet package you can set the `autoReferenced` attribute of a package inside the `packages.config` to `false`. _Currently this setting is not available from UI._
Expand Down Expand Up @@ -206,8 +255,8 @@ For those with projects using automated build solutions like [continuous integra

## Installation

- As a global tool using: `dotnet tool install --global NuGetForUnity.Cli`.
- If you don't have a tool manifest (local tool installation context) first create one with: `dotnet new tool-manifest`. Than install NuGetForUnity.Cli using: `dotnet tool install NuGetForUnity.Cli`.
- 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](https://learn.microsoft.com/en-us/dotnet/core/tools/global-tools).

Expand Down
9 changes: 9 additions & 0 deletions src/NuGetForUnity.Tests/Assets/Tests/Editor/NuGetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,11 @@ public void VersionComparisonEqual(string version1, string version2)
[TestCase("[1.0,2.0]", "1.0")]
[TestCase("[1.0,2.0]", "2.0")]
[TestCase("(1.0,2.0)", "1.5")]
[TestCase("(1.0,2.0)", "[1.5,]")]
[TestCase("(1.0,2.0)", "(1.5,)")]
[TestCase("[1.0,2.0]", "(1.5,)")]
[TestCase("(1.0,2.0]", "[2.0,]")]
[TestCase("[1.0,2.0]", "[0.1,1.0]")]
public void VersionInRangeTest(string versionRange, string version)
{
var id = new NugetPackageIdentifier("TestPackage", versionRange);
Expand All @@ -560,6 +565,10 @@ public void VersionInRangeTest(string versionRange, string version)
[TestCase("[1.0,2.0]", "3.0")]
[TestCase("(1.0,2.0)", "1.0")]
[TestCase("(1.0,2.0)", "2.0")]
[TestCase("(1.0,2.0)", "[2.0,]")]
[TestCase("(1.0,2.0]", "(2.0,]")]
[TestCase("[1.0,2.0]", "[0.1,1.0)")]
[TestCase("(1.0,2.0]", "[0.1,1.0]")]
public void VersionOutOfRangeTest(string versionRange, string version)
{
var id = new NugetPackageIdentifier("TestPackage", versionRange);
Expand Down
13 changes: 13 additions & 0 deletions src/NuGetForUnity/Editor/Configuration/NugetConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public class NugetConfigFile

private const string UpdateSearchBatchSizeAttributeName = "updateSearchBatchSize";

private const string SupportsPackageIdSearchFilterAttributeName = "supportsPackageIdSearchFilter";

/// <summary>
/// The incomplete path that is saved. The path is expanded and made public via the property above.
/// </summary>
Expand Down Expand Up @@ -184,6 +186,12 @@ public static NugetConfigFile Load([NotNull] string filePath)
{
sourceV3.UpdateSearchBatchSize = Mathf.Clamp(int.Parse(updateSearchBatchSizeString), 1, int.MaxValue);
}

var supportsPackageIdSearchFilterString = add.Attribute(SupportsPackageIdSearchFilterAttributeName)?.Value;
if (bool.TryParse(supportsPackageIdSearchFilterString, out var supportsPackageIdSearchFilter))
{
sourceV3.SupportsPackageIdSearchFilter = supportsPackageIdSearchFilter;
}
}

configFile.PackageSources.Add(newPackageSource);
Expand Down Expand Up @@ -403,6 +411,11 @@ public void Save([NotNull] string filePath)
{
addElement.Add(new XAttribute(UpdateSearchBatchSizeAttributeName, sourceV3.UpdateSearchBatchSize));
}

if (sourceV3.SupportsPackageIdSearchFilter != NugetPackageSourceV3.DefaultSupportsPackageIdSearchFilter)
{
addElement.Add(new XAttribute(SupportsPackageIdSearchFilterAttributeName, sourceV3.SupportsPackageIdSearchFilter));
}
}

packageSources.Add(addElement);
Expand Down
15 changes: 14 additions & 1 deletion src/NuGetForUnity/Editor/Models/NugetPackageV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ public List<NugetFrameworkGroup> Dependencies

return Task.Run(GetDependenciesCoreAsync).GetAwaiter().GetResult();
}

set
{
dependencies = value;
dependenciesFetched = true;
}
}

/// <inheritdoc />
Expand Down Expand Up @@ -198,6 +204,13 @@ public IReadOnlyList<INugetPackageIdentifier> CurrentFrameworkDependencies
}
}

/// <summary>
/// Gets or sets the URL for the location of the actual (.nupkg) NuGet package.
/// </summary>
[CanBeNull]
[field: SerializeField]
public string DownloadUrl { get; set; }

/// <inheritdoc />
IReadOnlyList<PluginAPI.Models.INugetPackageIdentifier> PluginAPI.Models.INugetPackage.CurrentFrameworkDependencies =>
CurrentFrameworkDependencies;
Expand All @@ -223,7 +236,7 @@ public Task<List<NugetFrameworkGroup>> GetDependenciesAsync()
/// <inheritdoc />
public void DownloadNupkgToFile(string outputFilePath)
{
packageSource.DownloadNupkgToFile(this, outputFilePath, null);
packageSource.DownloadNupkgToFile(this, outputFilePath, DownloadUrl);
}

/// <inheritdoc />
Expand Down
16 changes: 13 additions & 3 deletions src/NuGetForUnity/Editor/Models/NugetPackageVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,19 @@ public bool InRange([NotNull] NugetPackageVersion other)

if (other.HasVersionRange)
{
// either other or both have a version range specified. So it makes no sense to check if this is in the range of other.
// we can only check if the version ranges are equal.
return string.Equals(FullVersion, other.FullVersion, StringComparison.OrdinalIgnoreCase);
if (!HasVersionRange)
{
// A 'single' version can't be in range of a version range.
JoC0de marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

// We have two version ranges. We check if they intersect.
return (other.minimumSemVer2Version.HasValue &&
CompareVersion(other.minimumSemVer2Version.Value) == 0 &&
(other.IsMinInclusive || !other.minimumSemVer2Version.Equals(maximumSemVer2Version))) ||
(other.maximumSemVer2Version.HasValue &&
CompareVersion(other.maximumSemVer2Version.Value) == 0 &&
(other.IsMaxInclusive || !other.maximumSemVer2Version.Equals(minimumSemVer2Version)));
}

if (!HasVersionRange)
Expand Down
5 changes: 3 additions & 2 deletions src/NuGetForUnity/Editor/PackageSource/INugetPackageSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ public interface INugetPackageSource : IDisposable
string SavedPath { get; set; }

/// <summary>
/// Gets the explicitly defined protocol version stored inside the 'NuGet.config'.
/// Gets or sets the explicitly defined protocol version stored inside the 'NuGet.config'.
/// </summary>
/// <remarks>Changing this value will only take effect after reloading as it potentially need to change the type of the class.</remarks>
[CanBeNull]
string SavedProtocolVersion { get; }
string SavedProtocolVersion { get; set; }

/// <summary>
/// Gets or sets the user-name used to access the feed. Null indicates that no authentication is used.
Expand Down
Loading
Loading