I'm working on an ASP.NET Core project, where I have to grab information and packages from a Nuget feed. Everything works like a charm locally, but when I deploy the site and try to access the nuget feed, I get the following error:
Nuget.Configuration.NugetConfigurationException: Failed to read NuGet.Config due to unauthorized access. Path: c:\Windows\System32\Config\SystemProfile\AppData\Roaming\Nuget\Nuget.config
I tried many ways to instantiate the Nuget repository provider, but all of them ends with the same issue.
The code I use to create the repository source is as follows:
private SourceRepository GetRepository() { List<Lazy<INugetResourceProvider>> providers = new List<Lazy<INugetResourceProvider>>(); providers.AddRange(Repository.Provider.GetCoreV3()); var packageSource = new PackageSource(<feedurl>) { Credentials = new PackageSourceCredential(...) }; return new SourceRepository(packageSource, providers);}
It fails when tries to create theSourceRepository
.
I tried setting nuget file programmatically, even using environment variables. I even tried to add permission to the system folder, and it's not working anyway. Always the same issue.
- What identity (user) is used for the process accessing the NuGet API; and what's the ACL on the config file?Richard– Richard2025-09-25 19:47:57 +00:00CommentedSep 25 at 19:47
- From memory, IIS has a setting somewhere to tell it to "load profile" for the account that the pool or something is running as. Point is that it needs the user profile loaded.zivkan– zivkan2025-09-25 20:02:46 +00:00CommentedSep 25 at 20:02
- If you're accessing your github package feed, I think you still can't access it without authentication statePieterjan– Pieterjan2025-09-26 12:16:51 +00:00CommentedSep 26 at 12:16
- Richard, is using the App Identity of the pool. The file in this case, and in that location does not exists.Agustín Catellani– Agustín Catellani2025-09-26 15:46:34 +00:00CommentedSep 26 at 15:46