microsoft / artifacts-credprovider

The Azure Artifacts Credential Provider enables dotnet, NuGet.exe, and MSBuild to interactively acquire credentials for Azure Artifacts feeds.
MIT License
787 stars 705 forks source link

Do NuGet and MSBuild really need the netfx version to be installed? #536

Open CarlHeinrichs opened 23 hours ago

CarlHeinrichs commented 23 hours ago

The ReadMe at Credential Provider Setup says, "NuGet and MSBuild need the netfx version to be installed."

If I set my environment to use the net8 download of Credential Provider 1.3.0. It only has a netcore version available:

NUGET_PLUGIN_PATHS=C:\CxCache\Microsoft.Net8.NuGet.CredentialProvider.1.3.0\tools\plugins\netcore\CredentialProvider.Microsoft\CredentialProvider.Microsoft.exe;

nuget.exe 6.9.1 can connect to the ADO feed without issue and MSBuild version 17.11.2+c078802d4 for .NET Framework restores packages without issue.

C:\src>set nuget
NugetCommandLineTool=C:\CxCache\NuGet.CommandLine.6.9.1\tools\nuget.exe
NugetMachineInstallRoot=C:\CxCache
NUGET_CREDENTIALPROVIDER_FORCE_CANSHOWDIALOG_TO=True
NUGET_HTTP_CACHE_PATH=C:\.tools\.nuget\v3-cache
NUGET_PACKAGES=C:\.tools\.nuget\packages\
NUGET_PLUGINS_CACHE_PATH=C:\.tools\.nuget\plugins-cache
NUGET_PLUGIN_PATHS=C:\CxCache\Microsoft.Net8.NuGet.CredentialProvider.1.3.0\tools\plugins\netcore\CredentialProvider.Microsoft\CredentialProvider.Microsoft.exe;

C:\src>C:\CxCache\NuGet.CommandLine.6.9.1\tools\nuget.exe list polly
Microsoft.Extensions.Http.Polly 9.0.0
Microsoft.R9.Extensions.HttpClient.Resilience.Polly 1.32.1
Microsoft.R9.Extensions.Resilience.Polly 1.32.1
Polly 8.5.0
Polly-Signed 5.9.0
Polly.Caching.Memory 3.0.2
Polly.Contrib.Simmy 0.3.0
Polly.Contrib.WaitAndRetry 1.1.1
Polly.Core 8.5.0
Polly.Extensions 8.5.0
Polly.Extensions.Http 3.0.0
Polly.RateLimiting 8.5.0
Polly.StrongNameSigned 7.2.2

Is there bug in the wiki or some sort of scenario that I am missing?

nkolev92 commented 20 hours ago

NuGet in Visual Studio & MSBuild ship with the Credential Provider pre-installed.

So you don't need to install when only using msbuild /t:restore or a new enough version of NuGet.exe restore.

Note that environment variables do take precedence over the convention-based discovery, so if you set env vars, you won't be using the preinstalled one.

Documentation: https://learn.microsoft.com/en-us/nuget/consume-packages/consuming-packages-authenticated-feeds#credential-providers

In particular;

Visual Studio 2017 version 15.9, and above, includes a credential provider for [Azure Artifacts](https://learn.microsoft.com/en-us/azure/devops/artifacts/), that works within Visual Studio, MSBuild, and NuGet.exe. However, the credential provider for the .NET SDK is not included by Visual Studio, so [must be installed separately](https://github.com/microsoft/artifacts-credprovider?tab=readme-ov-file#setup) to work with the dotnet CLI.
CarlHeinrichs commented 15 hours ago

The point is that I do not need to install the NetFx version to work with MSBuild or NuGet command line. It seems like the Wiki is wrong when it says, "NuGet and MSBuild need the netfx version to be installed." I am able to install the Net8 Core version of the Credential Provider without the NetFx version and MSBuild and NuGet command line work great with Net core version.

It seems like what you are saying is that there is no need to install anything if you are using our retail products. But, if we are using a custom development environment (like most of Microsoft), it appears that the net Core version of Credential Provider works great with MSBuild and NuGet command line.

Please explain under which scenarios there is an incompatibility with the Net8 core Credential provider and MSBuild and NuGet command line?

nkolev92 commented 3 hours ago

Yeah, I don't think you need to install it. The wiki could use an update.

The NETFX version is only relevant when you're using MSBuild, which carries its own provider. To use NuGet.exe on a project, you also need MSBuild, which again brings that provider.

The netfx/netcore has everything to do with the runtime needed to start the plugin. If you tell netfx MSBuild to use the netcore provider, it might start-up, but it's not always guaranteed to work, since the runtime may not be available.

My recommendation: If you're using only netfx MSBuild /t:restore, do not install anything. Do not use the env var to point to cred provider and rely on the conventions.