xoofx/UnityNuGet

RegistryCache.cs: ignore Nuget.Config

nefelim4ag opened this issue · 3 comments

I tried to connect the custom NuGet source repo from Gitlab.
I assume - I just need to update Nuget.Config (because of auth & custom URL).
But ended up with a monkey patch like this (regardless of the defined source in Nuget.Config):

            _settings = Settings.LoadDefaultSettings(root: null);
            var sourceProvider = new PackageSourceProvider(_settings, new[]
            {
                new PackageSource("https://api.nuget.org/v3/index.json"),
                new PackageSource("https://gitlab.example.com/api/v4/projects/5/packages/nuget/index.json")
            });
            var sourceRepositoryProvider = new SourceRepositoryProvider(sourceProvider, Repository.Provider.GetCoreV3());
            _sourceRepositories = sourceRepositoryProvider.GetRepositories();

Without it, my custom packages only checked in api.nuget.org
So, with attention to examples/docker, maybe I did something wrong, and in that case, looks like some additional documentation is needed.

bdovaz commented

But the Nuget.Config file is mapped to docker? You haven't posted any examples of the tests you have done.

Have you looked at this example?

https://github.com/xoofx/UnityNuGet/tree/master/examples/docker

Some debug logs:

            _settings = Settings.LoadDefaultSettings(root: null);
            var sourceProvider = new PackageSourceProvider(_settings, new[]
            {
                new PackageSource("https://api.nuget.org/v3/index.json"),
                new PackageSource("https://gitlab.example.com/api/v4/projects/5/packages/nuget/index.json")
            });
            var sourceRepositoryProvider = new SourceRepositoryProvider(sourceProvider, Repository.Provider.GetCoreV3());
            _sourceRepositories = sourceRepositoryProvider.GetRepositories();
            _logger = logger;
            _registry = Registry.GetInstance();

            // Debug logs of original
            LogInformation("some logging information");
            LogInformation(string.Join(",", _settings.GetConfigFilePaths().ToArray()));
            var _source_provider = new PackageSourceProvider(_settings);
            LogInformation(string.Join(",", _source_provider.LoadPackageSources()));

Output:

info: NuGet[0]
      some logging information
info: NuGet[0]
      /root/.nuget/NuGet/NuGet.Config
info: NuGet[0]
      nuget.org [https://api.nuget.org/v3/index.json]

File (run in Kubernetes BTW):

root@unitynuget-6bdbfb449c-vn4sq:/app# cat /root/.nuget/NuGet/NuGet.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
  <packageSources>
      <clear />
      <add key="gitlab" value="https://gitlab.example.com/api/v4/projects/5/packages/nuget/index.json" />
  </packageSources>
  <packageSourceCredentials>
      <github>
          <add key="Username" value="deploy-token-9" />
          <add key="ClearTextPassword" value="redacted" />
      </github>
  </packageSourceCredentials>
</configuration>

My apologies, I lost the fix of XML in rebases, so the format was incorrect, and that is the reason.

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
        <packageSources>
          <clear />
          <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
          <add key="gitlab" value="https://gitlab.example.com/api/v4/projects/5/packages/nuget/index.json" />
        </packageSources>
        <packageSourceCredentials>
            <github>
                <add key="Username" value="deploy-token-9" />
                <add key="ClearTextPassword" value="redacted" />
            </github>
        </packageSourceCredentials>
      </configuration>