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

Specify package source as cli argument #928

Open
mattiaskagstrom opened this issue Nov 11, 2021 · 13 comments
Open

Specify package source as cli argument #928

mattiaskagstrom opened this issue Nov 11, 2021 · 13 comments
Labels
design-proposal label for issues that are design proposal Triaged Label to show that UA team has triaged this issue.

Comments

@mattiaskagstrom
Copy link

mattiaskagstrom commented Nov 11, 2021

Summary

Just as when installing the tool where you can supply a argument (--add-source) with a nuget feed, this is needed when running the upgrade aswell.

Motivation and goals

The analysis currently fails because it tries to fetch all packages from nuget.org, this feed is unavalible on our intranet.

Examples

dotnet has:
dotnet tool update -g upgrade-assistant --add-source proget/feed.json

upgrade-assiatnat should have:
upgrade-assistant analyze project.csproj --add-source proget/feed.json

@mattiaskagstrom mattiaskagstrom added the design-proposal label for issues that are design proposal label Nov 11, 2021
@tomasscott
Copy link

Indeed - this is needed!

@twsouthwick
Copy link
Member

We honor what is provided in the NuGet.config. Is there a reason that is not sufficient?

@sunandabalu sunandabalu added the Triaged Label to show that UA team has triaged this issue. label Nov 11, 2021
@mattiaskagstrom
Copy link
Author

our internal feed is specified both in %appdata%\NuGet\NuGet.Config and in C:\Program Files (x86)\NuGet\Config\NuGet.Config. Upgrade-assistant still fetches from nuget.org.

@twsouthwick
Copy link
Member

Oh interesting. We should be checking that so we should check on that

@rasenschachmatt
Copy link

Same here, this is really needed in a production development environment that is not fully connected to the internet for security reasons.

@Jakub-Nalewajek-vcbs
Copy link

@twsouthwick are you tracking the issue for connecting to Nuget feeds other than nuget.org despite them being provided nuget.config in another ticket?

@swythan
Copy link

swythan commented Sep 26, 2022

I'm seeing this too. In my environment we can't connect directly to nuget.org, but we have got an on-prem server that proxies through.

I tried using a nuget.config file with a packageSources section that cleared the existing sources and just added our feed, and it still hung during analyze. I debugged in with VS, and it was blocked trying to access nuget.org.

@swythan
Copy link

swythan commented Sep 27, 2022

I think the way the tool finds your nuget config might have got broken in #824.

See my comment: #824 (comment)

EDIT: I've confirmed (by patching with dnSpy) that forcing NuGetPackageSourceFactory.GetPackageSources(path) to use the source folder of my app will get upgrade-assistant to use the package sources in my nuget.config and work correctly.

@marijnz0r
Copy link

I'm experiencing problems behind a proxy as well.
@swythan could you be so kind to provide an example how to use your workaround?

@mattiaskagstrom
Copy link
Author

@swythan Do you think you are able to create a pull request with your patch? (and tag this issue)

@swythan
Copy link

swythan commented Sep 30, 2022

Sorry I didn't patch it properly I just used dnSpy to inject a useful value for the project path at an opportune point. I just wanted to try it out first. I could see that it's not trivial to get the relevant bit of config where it needs to be since #824 (which is presumably why it got lost).

As it turns out the tool wasn't useful for me in the end. I'd not realised that all the really useful capabilities are only really meant for going from .NET Framework to .NET (Core). I was looking for help upgrading between older versions of .NET Core/Standard to .NET 6.

@swythan
Copy link

swythan commented Sep 30, 2022

Specifically I used dnSpy to:

  1. Load up %USERPROFILE%\.dotnet\tools\.store\upgrade-assistant\0.4.346202\upgrade-assistant\0.4.346202\tools\net6.0\any\extensions\nuget\Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet.dll.
  2. Go to NuGetPackageSourceFactory in Microsoft.DotNet.UpgradeAssistant.Extensions.NuGet
  3. Right-click GetPackageSources and select "Edit Method (C#)"
  4. Add the following near the top of the method and click "Compile"
			if (path == null)
			{
				path = Environment.CurrentDirectory;
			}
  1. Fix the compiler errors about NullableAttribute, etc by deleting the attributes until the compile works.
  2. "File -> Save Module..." and accept the defaults

Now run the tool with the current directory where your nuget.config file is.

@arif-b-khan
Copy link

arif-b-khan commented Feb 28, 2023

In my case we're pointing to internal repositories (we cannot restore packages from "api.nuget.org"). I've set the configuration in appsettings.json. I tried updating the "Source" parameter in appsettings.json. It is still picking up "https://api.nuget.org/v3/index.json". I also tried adding parameter --add-source. This command is not working. I don't understand why upgrade-assistant is not picking up the repositories defined in my global configuration for i.e %appdata%/NuGet/NuGet.config. I looked into the source code and found this method "NuGetPackageSourceFactory.GetPackageSources" is taking "PackageSourcePath" as parameter. To set "PackageSourcePath" explicitly I added the following configuration in appsetting.json
"NuGetDownloaderOptions":{ "PackageSourcePath": "https://enterprise.example.com/index.json" }
The above configuration didn't work. Upgrade-assistant cli picks up the "https://api.nuget.org/v3/index.json".

Can somebody help me with this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design-proposal label for issues that are design proposal Triaged Label to show that UA team has triaged this issue.
Projects
None yet
Development

No branches or pull requests

9 participants