Get Nuget credentials stored somewhere by Visual Studio in a VSIX project
up vote
0
down vote
favorite
I'm developing a Visual Studio extension (VSIX project) that needs to manage Nuget packages of a given project.
I'm already using the IVsPackageInstaller
service as documented here but this is limited and I need more features (for example get the latest version number of a given package).
I searched but didn't find anything on how to programmatically interact with the Visual Studio Package Manager so I decided to go for the Nuget API directly.
I send HTTP requests to the Nuget API using the WebRequest
class (because we can't use HttpClient
in a VSIX project) but I'm hitting a problem: the requests are going to a private Nuget feed that needs authentication! (hosted on Azure DevOps)
I used Fiddler to check the HTTP requests sent to our Azure DevOps server. I see a POST request going to https://app.vssps.visualstudio.com/_apis/Token/SessionTokens
with a token in response but this is not the Token I'm looking for.
The token passed to the Nuget API is a Basic
token that comes from I don't know where. I couldn't find this token anywhere in the HTTP responses I caught.
I can also see that some responses to our Azure DevOps server contain some headers like this (I changed the GUID)
WWW-Authenticate: Bearer authorization_uri=https://login.windows.net/ce372fcc-5e17-490b-ad99-47565dac8a84
I can find this GUID back in the %userprofile%AppDataLocal.IdentityServiceAccountStore.json
file, there is definitely something going on here. And the SessionTokens.json
file in the same folder looks reeeaaally interesting too but it's encrypted...
I also tried to dig in the Registry to see if I can find interesting information for example at the path specified in Simon's comment but it seems VS2017 doesn't store the token there anymore.
I also loaded the privateregistry.bin
file (aka the Visual Studio Settings Store
) and searched everywhere but couldn't find anything.
So instead of trying to reverse engineer Visual Studio I wanted to access its Credential Provider directly. I tried to access to several services and classes
var componentModel = await ServiceProvider.GetGlobalServiceAsync(typeof(SComponentModel)) as IComponentModel;
var credentialProvider = componentModel.GetService<IVsCredentialProvider>();
var credentialServiceProvider = componentModel.GetService<ICredentialServiceProvider>();
var defaultCredentialServiceProvider = new DefaultVSCredentialServiceProvider();
But none of them are working (return null or Exception).
I wandered in the NuGet.PackageManagement.VisualStudio project on Github but couldn't find my answer.
There are also many Nuget packages like NuGet.PackageManagement.VisualStudio
, Microsoft.VisualStudio.Services.Release.Client
, Microsoft.VisualStudio.Services.ExtensionManagement.WebApi
, Microsoft.VisualStudio.Services.InteractiveClient
just to name a few but honestly I don't know if what I'm looking for is there...
So how to access the Nuget credentials used by Visual Studio?
I take any solution that gives me access to all the reading Nuget features, for example programmatically use the Visual Studio Package Management, or decrypt this SessionTokens.json
file or access the Visual Studio Credential Provider.
The less hacky is the answer, the better it is of couse.
At this point you probably already guessed, I don't want to store the username
and password
somewhere myself. I need to create a user-friendly VS extension, that's why I want to retrieve and use the credentials already saved in Visual Studio by the users.
Thank you so much if you can solve this problem.
c# visual-studio nuget visual-studio-extensions vsix
add a comment |
up vote
0
down vote
favorite
I'm developing a Visual Studio extension (VSIX project) that needs to manage Nuget packages of a given project.
I'm already using the IVsPackageInstaller
service as documented here but this is limited and I need more features (for example get the latest version number of a given package).
I searched but didn't find anything on how to programmatically interact with the Visual Studio Package Manager so I decided to go for the Nuget API directly.
I send HTTP requests to the Nuget API using the WebRequest
class (because we can't use HttpClient
in a VSIX project) but I'm hitting a problem: the requests are going to a private Nuget feed that needs authentication! (hosted on Azure DevOps)
I used Fiddler to check the HTTP requests sent to our Azure DevOps server. I see a POST request going to https://app.vssps.visualstudio.com/_apis/Token/SessionTokens
with a token in response but this is not the Token I'm looking for.
The token passed to the Nuget API is a Basic
token that comes from I don't know where. I couldn't find this token anywhere in the HTTP responses I caught.
I can also see that some responses to our Azure DevOps server contain some headers like this (I changed the GUID)
WWW-Authenticate: Bearer authorization_uri=https://login.windows.net/ce372fcc-5e17-490b-ad99-47565dac8a84
I can find this GUID back in the %userprofile%AppDataLocal.IdentityServiceAccountStore.json
file, there is definitely something going on here. And the SessionTokens.json
file in the same folder looks reeeaaally interesting too but it's encrypted...
I also tried to dig in the Registry to see if I can find interesting information for example at the path specified in Simon's comment but it seems VS2017 doesn't store the token there anymore.
I also loaded the privateregistry.bin
file (aka the Visual Studio Settings Store
) and searched everywhere but couldn't find anything.
So instead of trying to reverse engineer Visual Studio I wanted to access its Credential Provider directly. I tried to access to several services and classes
var componentModel = await ServiceProvider.GetGlobalServiceAsync(typeof(SComponentModel)) as IComponentModel;
var credentialProvider = componentModel.GetService<IVsCredentialProvider>();
var credentialServiceProvider = componentModel.GetService<ICredentialServiceProvider>();
var defaultCredentialServiceProvider = new DefaultVSCredentialServiceProvider();
But none of them are working (return null or Exception).
I wandered in the NuGet.PackageManagement.VisualStudio project on Github but couldn't find my answer.
There are also many Nuget packages like NuGet.PackageManagement.VisualStudio
, Microsoft.VisualStudio.Services.Release.Client
, Microsoft.VisualStudio.Services.ExtensionManagement.WebApi
, Microsoft.VisualStudio.Services.InteractiveClient
just to name a few but honestly I don't know if what I'm looking for is there...
So how to access the Nuget credentials used by Visual Studio?
I take any solution that gives me access to all the reading Nuget features, for example programmatically use the Visual Studio Package Management, or decrypt this SessionTokens.json
file or access the Visual Studio Credential Provider.
The less hacky is the answer, the better it is of couse.
At this point you probably already guessed, I don't want to store the username
and password
somewhere myself. I need to create a user-friendly VS extension, that's why I want to retrieve and use the credentials already saved in Visual Studio by the users.
Thank you so much if you can solve this problem.
c# visual-studio nuget visual-studio-extensions vsix
Why don't you use the nuget client API? github.com/NuGet/NuGet.Client that's what Visual Studio uses.
– Simon Mourier
Nov 8 at 11:21
Wow thanks a lot, honestly I'm a bit surprised the only documentation about that is an unofficial blog post from 2016. This solves my Nuget issue but I'm stubborn and I like to understand when I'm facing a problem. Do developers can officially access VS stored credentials using a service provider? If yes how can we do? Thanks for your answer
– Jérôme MEVEL
Nov 9 at 3:23
There are some drawbacks of everything being now opensourced. What's official is now a grey zone, and the documentation has been considerably reduced. We as developers are now on our own... Many VS packages are now using MEF, so I think you can ask MEF for the ICredentialServiceProvider interface defined in NuGet.PackageManagement.VisualStudio for example. If you want to get deeper, just analyze how this is implemented. Visual Studio code base is huge, good luck :-)
– Simon Mourier
Nov 9 at 7:00
That's the thing, I triedcomponentModel.GetService<ICredentialServiceProvider>()
but it didn't give me any actual credential provider. Yeah it's huge and I got lost in all that code, that's why I was hoping you had the magic answer. But thanks, you helped me a lot by pointing toNuGet.Client
. With all that code, I completely got lost about what thing I was supposed to use.
– Jérôme MEVEL
Nov 9 at 8:20
1
You should provide a small repro sample
– Simon Mourier
Nov 9 at 8:35
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm developing a Visual Studio extension (VSIX project) that needs to manage Nuget packages of a given project.
I'm already using the IVsPackageInstaller
service as documented here but this is limited and I need more features (for example get the latest version number of a given package).
I searched but didn't find anything on how to programmatically interact with the Visual Studio Package Manager so I decided to go for the Nuget API directly.
I send HTTP requests to the Nuget API using the WebRequest
class (because we can't use HttpClient
in a VSIX project) but I'm hitting a problem: the requests are going to a private Nuget feed that needs authentication! (hosted on Azure DevOps)
I used Fiddler to check the HTTP requests sent to our Azure DevOps server. I see a POST request going to https://app.vssps.visualstudio.com/_apis/Token/SessionTokens
with a token in response but this is not the Token I'm looking for.
The token passed to the Nuget API is a Basic
token that comes from I don't know where. I couldn't find this token anywhere in the HTTP responses I caught.
I can also see that some responses to our Azure DevOps server contain some headers like this (I changed the GUID)
WWW-Authenticate: Bearer authorization_uri=https://login.windows.net/ce372fcc-5e17-490b-ad99-47565dac8a84
I can find this GUID back in the %userprofile%AppDataLocal.IdentityServiceAccountStore.json
file, there is definitely something going on here. And the SessionTokens.json
file in the same folder looks reeeaaally interesting too but it's encrypted...
I also tried to dig in the Registry to see if I can find interesting information for example at the path specified in Simon's comment but it seems VS2017 doesn't store the token there anymore.
I also loaded the privateregistry.bin
file (aka the Visual Studio Settings Store
) and searched everywhere but couldn't find anything.
So instead of trying to reverse engineer Visual Studio I wanted to access its Credential Provider directly. I tried to access to several services and classes
var componentModel = await ServiceProvider.GetGlobalServiceAsync(typeof(SComponentModel)) as IComponentModel;
var credentialProvider = componentModel.GetService<IVsCredentialProvider>();
var credentialServiceProvider = componentModel.GetService<ICredentialServiceProvider>();
var defaultCredentialServiceProvider = new DefaultVSCredentialServiceProvider();
But none of them are working (return null or Exception).
I wandered in the NuGet.PackageManagement.VisualStudio project on Github but couldn't find my answer.
There are also many Nuget packages like NuGet.PackageManagement.VisualStudio
, Microsoft.VisualStudio.Services.Release.Client
, Microsoft.VisualStudio.Services.ExtensionManagement.WebApi
, Microsoft.VisualStudio.Services.InteractiveClient
just to name a few but honestly I don't know if what I'm looking for is there...
So how to access the Nuget credentials used by Visual Studio?
I take any solution that gives me access to all the reading Nuget features, for example programmatically use the Visual Studio Package Management, or decrypt this SessionTokens.json
file or access the Visual Studio Credential Provider.
The less hacky is the answer, the better it is of couse.
At this point you probably already guessed, I don't want to store the username
and password
somewhere myself. I need to create a user-friendly VS extension, that's why I want to retrieve and use the credentials already saved in Visual Studio by the users.
Thank you so much if you can solve this problem.
c# visual-studio nuget visual-studio-extensions vsix
I'm developing a Visual Studio extension (VSIX project) that needs to manage Nuget packages of a given project.
I'm already using the IVsPackageInstaller
service as documented here but this is limited and I need more features (for example get the latest version number of a given package).
I searched but didn't find anything on how to programmatically interact with the Visual Studio Package Manager so I decided to go for the Nuget API directly.
I send HTTP requests to the Nuget API using the WebRequest
class (because we can't use HttpClient
in a VSIX project) but I'm hitting a problem: the requests are going to a private Nuget feed that needs authentication! (hosted on Azure DevOps)
I used Fiddler to check the HTTP requests sent to our Azure DevOps server. I see a POST request going to https://app.vssps.visualstudio.com/_apis/Token/SessionTokens
with a token in response but this is not the Token I'm looking for.
The token passed to the Nuget API is a Basic
token that comes from I don't know where. I couldn't find this token anywhere in the HTTP responses I caught.
I can also see that some responses to our Azure DevOps server contain some headers like this (I changed the GUID)
WWW-Authenticate: Bearer authorization_uri=https://login.windows.net/ce372fcc-5e17-490b-ad99-47565dac8a84
I can find this GUID back in the %userprofile%AppDataLocal.IdentityServiceAccountStore.json
file, there is definitely something going on here. And the SessionTokens.json
file in the same folder looks reeeaaally interesting too but it's encrypted...
I also tried to dig in the Registry to see if I can find interesting information for example at the path specified in Simon's comment but it seems VS2017 doesn't store the token there anymore.
I also loaded the privateregistry.bin
file (aka the Visual Studio Settings Store
) and searched everywhere but couldn't find anything.
So instead of trying to reverse engineer Visual Studio I wanted to access its Credential Provider directly. I tried to access to several services and classes
var componentModel = await ServiceProvider.GetGlobalServiceAsync(typeof(SComponentModel)) as IComponentModel;
var credentialProvider = componentModel.GetService<IVsCredentialProvider>();
var credentialServiceProvider = componentModel.GetService<ICredentialServiceProvider>();
var defaultCredentialServiceProvider = new DefaultVSCredentialServiceProvider();
But none of them are working (return null or Exception).
I wandered in the NuGet.PackageManagement.VisualStudio project on Github but couldn't find my answer.
There are also many Nuget packages like NuGet.PackageManagement.VisualStudio
, Microsoft.VisualStudio.Services.Release.Client
, Microsoft.VisualStudio.Services.ExtensionManagement.WebApi
, Microsoft.VisualStudio.Services.InteractiveClient
just to name a few but honestly I don't know if what I'm looking for is there...
So how to access the Nuget credentials used by Visual Studio?
I take any solution that gives me access to all the reading Nuget features, for example programmatically use the Visual Studio Package Management, or decrypt this SessionTokens.json
file or access the Visual Studio Credential Provider.
The less hacky is the answer, the better it is of couse.
At this point you probably already guessed, I don't want to store the username
and password
somewhere myself. I need to create a user-friendly VS extension, that's why I want to retrieve and use the credentials already saved in Visual Studio by the users.
Thank you so much if you can solve this problem.
c# visual-studio nuget visual-studio-extensions vsix
c# visual-studio nuget visual-studio-extensions vsix
asked Nov 8 at 9:53
Jérôme MEVEL
1,3971735
1,3971735
Why don't you use the nuget client API? github.com/NuGet/NuGet.Client that's what Visual Studio uses.
– Simon Mourier
Nov 8 at 11:21
Wow thanks a lot, honestly I'm a bit surprised the only documentation about that is an unofficial blog post from 2016. This solves my Nuget issue but I'm stubborn and I like to understand when I'm facing a problem. Do developers can officially access VS stored credentials using a service provider? If yes how can we do? Thanks for your answer
– Jérôme MEVEL
Nov 9 at 3:23
There are some drawbacks of everything being now opensourced. What's official is now a grey zone, and the documentation has been considerably reduced. We as developers are now on our own... Many VS packages are now using MEF, so I think you can ask MEF for the ICredentialServiceProvider interface defined in NuGet.PackageManagement.VisualStudio for example. If you want to get deeper, just analyze how this is implemented. Visual Studio code base is huge, good luck :-)
– Simon Mourier
Nov 9 at 7:00
That's the thing, I triedcomponentModel.GetService<ICredentialServiceProvider>()
but it didn't give me any actual credential provider. Yeah it's huge and I got lost in all that code, that's why I was hoping you had the magic answer. But thanks, you helped me a lot by pointing toNuGet.Client
. With all that code, I completely got lost about what thing I was supposed to use.
– Jérôme MEVEL
Nov 9 at 8:20
1
You should provide a small repro sample
– Simon Mourier
Nov 9 at 8:35
add a comment |
Why don't you use the nuget client API? github.com/NuGet/NuGet.Client that's what Visual Studio uses.
– Simon Mourier
Nov 8 at 11:21
Wow thanks a lot, honestly I'm a bit surprised the only documentation about that is an unofficial blog post from 2016. This solves my Nuget issue but I'm stubborn and I like to understand when I'm facing a problem. Do developers can officially access VS stored credentials using a service provider? If yes how can we do? Thanks for your answer
– Jérôme MEVEL
Nov 9 at 3:23
There are some drawbacks of everything being now opensourced. What's official is now a grey zone, and the documentation has been considerably reduced. We as developers are now on our own... Many VS packages are now using MEF, so I think you can ask MEF for the ICredentialServiceProvider interface defined in NuGet.PackageManagement.VisualStudio for example. If you want to get deeper, just analyze how this is implemented. Visual Studio code base is huge, good luck :-)
– Simon Mourier
Nov 9 at 7:00
That's the thing, I triedcomponentModel.GetService<ICredentialServiceProvider>()
but it didn't give me any actual credential provider. Yeah it's huge and I got lost in all that code, that's why I was hoping you had the magic answer. But thanks, you helped me a lot by pointing toNuGet.Client
. With all that code, I completely got lost about what thing I was supposed to use.
– Jérôme MEVEL
Nov 9 at 8:20
1
You should provide a small repro sample
– Simon Mourier
Nov 9 at 8:35
Why don't you use the nuget client API? github.com/NuGet/NuGet.Client that's what Visual Studio uses.
– Simon Mourier
Nov 8 at 11:21
Why don't you use the nuget client API? github.com/NuGet/NuGet.Client that's what Visual Studio uses.
– Simon Mourier
Nov 8 at 11:21
Wow thanks a lot, honestly I'm a bit surprised the only documentation about that is an unofficial blog post from 2016. This solves my Nuget issue but I'm stubborn and I like to understand when I'm facing a problem. Do developers can officially access VS stored credentials using a service provider? If yes how can we do? Thanks for your answer
– Jérôme MEVEL
Nov 9 at 3:23
Wow thanks a lot, honestly I'm a bit surprised the only documentation about that is an unofficial blog post from 2016. This solves my Nuget issue but I'm stubborn and I like to understand when I'm facing a problem. Do developers can officially access VS stored credentials using a service provider? If yes how can we do? Thanks for your answer
– Jérôme MEVEL
Nov 9 at 3:23
There are some drawbacks of everything being now opensourced. What's official is now a grey zone, and the documentation has been considerably reduced. We as developers are now on our own... Many VS packages are now using MEF, so I think you can ask MEF for the ICredentialServiceProvider interface defined in NuGet.PackageManagement.VisualStudio for example. If you want to get deeper, just analyze how this is implemented. Visual Studio code base is huge, good luck :-)
– Simon Mourier
Nov 9 at 7:00
There are some drawbacks of everything being now opensourced. What's official is now a grey zone, and the documentation has been considerably reduced. We as developers are now on our own... Many VS packages are now using MEF, so I think you can ask MEF for the ICredentialServiceProvider interface defined in NuGet.PackageManagement.VisualStudio for example. If you want to get deeper, just analyze how this is implemented. Visual Studio code base is huge, good luck :-)
– Simon Mourier
Nov 9 at 7:00
That's the thing, I tried
componentModel.GetService<ICredentialServiceProvider>()
but it didn't give me any actual credential provider. Yeah it's huge and I got lost in all that code, that's why I was hoping you had the magic answer. But thanks, you helped me a lot by pointing to NuGet.Client
. With all that code, I completely got lost about what thing I was supposed to use.– Jérôme MEVEL
Nov 9 at 8:20
That's the thing, I tried
componentModel.GetService<ICredentialServiceProvider>()
but it didn't give me any actual credential provider. Yeah it's huge and I got lost in all that code, that's why I was hoping you had the magic answer. But thanks, you helped me a lot by pointing to NuGet.Client
. With all that code, I completely got lost about what thing I was supposed to use.– Jérôme MEVEL
Nov 9 at 8:20
1
1
You should provide a small repro sample
– Simon Mourier
Nov 9 at 8:35
You should provide a small repro sample
– Simon Mourier
Nov 9 at 8:35
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
NuGet Client SDK
Thanks a lot to Simon who pointed me in the direction of NuGet.Client.
The only documentation from Microsoft is linking a 2016 blog post from Dave Glick but they also give a nice note:
These blog posts were written shortly after the 3.4.3 version of the NuGet client SDK packages were released. Newer versions of the packages may be incompatible with the information in the blog posts.
Alright, then I guess we will do with Dave's blog...
You should install two packages: NuGet.Client and Nuget.Protocol
Then here is the code for example to get the last version of a package:
using NuGet.Configuration;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MyProject
{
public class NugetHelper
{
public async Task<string> GetLatestVersionNumberFromNugetFeedAsync(NugetPackage package)
{
try
{
Logger logger = new Logger(); //Just a class implementing the Nuget.Common.ILogger interface
List<Lazy<INuGetResourceProvider>> providers = new List<Lazy<INuGetResourceProvider>>();
providers.AddRange(Repository.Provider.GetCoreV3()); // Add v3 API support
PackageSource packageSource = new PackageSource(package.Source.ToString());
SourceRepository sourceRepository = new SourceRepository(packageSource, providers);
PackageMetadataResource packageMetadataResource = await sourceRepository.GetResourceAsync<PackageMetadataResource>();
var searchMetadata = await packageMetadataResource.GetMetadataAsync(package.Name, false, false, new SourceCacheContext(), logger, new CancellationToken());
var versionNumber = searchMetadata.FirstOrDefault().Identity.Version.OriginalVersion;
return versionNumber;
}
catch (Exception ex)
{
return null;
}
}
}
public class NugetPackage
{
public string Name { get; set; }
public string Version { get; set; }
public string MinimumVersion { get; set; }
public Uri Source { get; set; }
}
}
Visual Studio credentials provider
The NuGet Client SDK solves my issue but doesn't actually answer to this SO question.
As I said, I tried to call
var componentModel = await ServiceProvider.GetGlobalServiceAsync(typeof(SComponentModel)) as IComponentModel;
componentModel.GetService<ICredentialServiceProvider>()
But this didn't work, so if anybody knows how to access the Visual Studio credentials provider, I would be really glad to know the answer.
Great, thanks for sharing your solution here, you could Accept it as an Answer. This can be beneficial to other community members reading this thread and we could close this thread, thanks.
– Leo Liu-MSFT
yesterday
1
It solves my problem but doesn't actually fully answer my question. I started creating a sample project as suggested by Simon but I don't have much time right now. I'm also still investigating the changes made by VS to the Registry. I will mark it as accepted when all of this is done. I'm not fully satisfied with the state of my answer for the moment.
– Jérôme MEVEL
yesterday
That would be great, thank you for your contribution :).
– Leo Liu-MSFT
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
NuGet Client SDK
Thanks a lot to Simon who pointed me in the direction of NuGet.Client.
The only documentation from Microsoft is linking a 2016 blog post from Dave Glick but they also give a nice note:
These blog posts were written shortly after the 3.4.3 version of the NuGet client SDK packages were released. Newer versions of the packages may be incompatible with the information in the blog posts.
Alright, then I guess we will do with Dave's blog...
You should install two packages: NuGet.Client and Nuget.Protocol
Then here is the code for example to get the last version of a package:
using NuGet.Configuration;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MyProject
{
public class NugetHelper
{
public async Task<string> GetLatestVersionNumberFromNugetFeedAsync(NugetPackage package)
{
try
{
Logger logger = new Logger(); //Just a class implementing the Nuget.Common.ILogger interface
List<Lazy<INuGetResourceProvider>> providers = new List<Lazy<INuGetResourceProvider>>();
providers.AddRange(Repository.Provider.GetCoreV3()); // Add v3 API support
PackageSource packageSource = new PackageSource(package.Source.ToString());
SourceRepository sourceRepository = new SourceRepository(packageSource, providers);
PackageMetadataResource packageMetadataResource = await sourceRepository.GetResourceAsync<PackageMetadataResource>();
var searchMetadata = await packageMetadataResource.GetMetadataAsync(package.Name, false, false, new SourceCacheContext(), logger, new CancellationToken());
var versionNumber = searchMetadata.FirstOrDefault().Identity.Version.OriginalVersion;
return versionNumber;
}
catch (Exception ex)
{
return null;
}
}
}
public class NugetPackage
{
public string Name { get; set; }
public string Version { get; set; }
public string MinimumVersion { get; set; }
public Uri Source { get; set; }
}
}
Visual Studio credentials provider
The NuGet Client SDK solves my issue but doesn't actually answer to this SO question.
As I said, I tried to call
var componentModel = await ServiceProvider.GetGlobalServiceAsync(typeof(SComponentModel)) as IComponentModel;
componentModel.GetService<ICredentialServiceProvider>()
But this didn't work, so if anybody knows how to access the Visual Studio credentials provider, I would be really glad to know the answer.
Great, thanks for sharing your solution here, you could Accept it as an Answer. This can be beneficial to other community members reading this thread and we could close this thread, thanks.
– Leo Liu-MSFT
yesterday
1
It solves my problem but doesn't actually fully answer my question. I started creating a sample project as suggested by Simon but I don't have much time right now. I'm also still investigating the changes made by VS to the Registry. I will mark it as accepted when all of this is done. I'm not fully satisfied with the state of my answer for the moment.
– Jérôme MEVEL
yesterday
That would be great, thank you for your contribution :).
– Leo Liu-MSFT
yesterday
add a comment |
up vote
0
down vote
NuGet Client SDK
Thanks a lot to Simon who pointed me in the direction of NuGet.Client.
The only documentation from Microsoft is linking a 2016 blog post from Dave Glick but they also give a nice note:
These blog posts were written shortly after the 3.4.3 version of the NuGet client SDK packages were released. Newer versions of the packages may be incompatible with the information in the blog posts.
Alright, then I guess we will do with Dave's blog...
You should install two packages: NuGet.Client and Nuget.Protocol
Then here is the code for example to get the last version of a package:
using NuGet.Configuration;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MyProject
{
public class NugetHelper
{
public async Task<string> GetLatestVersionNumberFromNugetFeedAsync(NugetPackage package)
{
try
{
Logger logger = new Logger(); //Just a class implementing the Nuget.Common.ILogger interface
List<Lazy<INuGetResourceProvider>> providers = new List<Lazy<INuGetResourceProvider>>();
providers.AddRange(Repository.Provider.GetCoreV3()); // Add v3 API support
PackageSource packageSource = new PackageSource(package.Source.ToString());
SourceRepository sourceRepository = new SourceRepository(packageSource, providers);
PackageMetadataResource packageMetadataResource = await sourceRepository.GetResourceAsync<PackageMetadataResource>();
var searchMetadata = await packageMetadataResource.GetMetadataAsync(package.Name, false, false, new SourceCacheContext(), logger, new CancellationToken());
var versionNumber = searchMetadata.FirstOrDefault().Identity.Version.OriginalVersion;
return versionNumber;
}
catch (Exception ex)
{
return null;
}
}
}
public class NugetPackage
{
public string Name { get; set; }
public string Version { get; set; }
public string MinimumVersion { get; set; }
public Uri Source { get; set; }
}
}
Visual Studio credentials provider
The NuGet Client SDK solves my issue but doesn't actually answer to this SO question.
As I said, I tried to call
var componentModel = await ServiceProvider.GetGlobalServiceAsync(typeof(SComponentModel)) as IComponentModel;
componentModel.GetService<ICredentialServiceProvider>()
But this didn't work, so if anybody knows how to access the Visual Studio credentials provider, I would be really glad to know the answer.
Great, thanks for sharing your solution here, you could Accept it as an Answer. This can be beneficial to other community members reading this thread and we could close this thread, thanks.
– Leo Liu-MSFT
yesterday
1
It solves my problem but doesn't actually fully answer my question. I started creating a sample project as suggested by Simon but I don't have much time right now. I'm also still investigating the changes made by VS to the Registry. I will mark it as accepted when all of this is done. I'm not fully satisfied with the state of my answer for the moment.
– Jérôme MEVEL
yesterday
That would be great, thank you for your contribution :).
– Leo Liu-MSFT
yesterday
add a comment |
up vote
0
down vote
up vote
0
down vote
NuGet Client SDK
Thanks a lot to Simon who pointed me in the direction of NuGet.Client.
The only documentation from Microsoft is linking a 2016 blog post from Dave Glick but they also give a nice note:
These blog posts were written shortly after the 3.4.3 version of the NuGet client SDK packages were released. Newer versions of the packages may be incompatible with the information in the blog posts.
Alright, then I guess we will do with Dave's blog...
You should install two packages: NuGet.Client and Nuget.Protocol
Then here is the code for example to get the last version of a package:
using NuGet.Configuration;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MyProject
{
public class NugetHelper
{
public async Task<string> GetLatestVersionNumberFromNugetFeedAsync(NugetPackage package)
{
try
{
Logger logger = new Logger(); //Just a class implementing the Nuget.Common.ILogger interface
List<Lazy<INuGetResourceProvider>> providers = new List<Lazy<INuGetResourceProvider>>();
providers.AddRange(Repository.Provider.GetCoreV3()); // Add v3 API support
PackageSource packageSource = new PackageSource(package.Source.ToString());
SourceRepository sourceRepository = new SourceRepository(packageSource, providers);
PackageMetadataResource packageMetadataResource = await sourceRepository.GetResourceAsync<PackageMetadataResource>();
var searchMetadata = await packageMetadataResource.GetMetadataAsync(package.Name, false, false, new SourceCacheContext(), logger, new CancellationToken());
var versionNumber = searchMetadata.FirstOrDefault().Identity.Version.OriginalVersion;
return versionNumber;
}
catch (Exception ex)
{
return null;
}
}
}
public class NugetPackage
{
public string Name { get; set; }
public string Version { get; set; }
public string MinimumVersion { get; set; }
public Uri Source { get; set; }
}
}
Visual Studio credentials provider
The NuGet Client SDK solves my issue but doesn't actually answer to this SO question.
As I said, I tried to call
var componentModel = await ServiceProvider.GetGlobalServiceAsync(typeof(SComponentModel)) as IComponentModel;
componentModel.GetService<ICredentialServiceProvider>()
But this didn't work, so if anybody knows how to access the Visual Studio credentials provider, I would be really glad to know the answer.
NuGet Client SDK
Thanks a lot to Simon who pointed me in the direction of NuGet.Client.
The only documentation from Microsoft is linking a 2016 blog post from Dave Glick but they also give a nice note:
These blog posts were written shortly after the 3.4.3 version of the NuGet client SDK packages were released. Newer versions of the packages may be incompatible with the information in the blog posts.
Alright, then I guess we will do with Dave's blog...
You should install two packages: NuGet.Client and Nuget.Protocol
Then here is the code for example to get the last version of a package:
using NuGet.Configuration;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MyProject
{
public class NugetHelper
{
public async Task<string> GetLatestVersionNumberFromNugetFeedAsync(NugetPackage package)
{
try
{
Logger logger = new Logger(); //Just a class implementing the Nuget.Common.ILogger interface
List<Lazy<INuGetResourceProvider>> providers = new List<Lazy<INuGetResourceProvider>>();
providers.AddRange(Repository.Provider.GetCoreV3()); // Add v3 API support
PackageSource packageSource = new PackageSource(package.Source.ToString());
SourceRepository sourceRepository = new SourceRepository(packageSource, providers);
PackageMetadataResource packageMetadataResource = await sourceRepository.GetResourceAsync<PackageMetadataResource>();
var searchMetadata = await packageMetadataResource.GetMetadataAsync(package.Name, false, false, new SourceCacheContext(), logger, new CancellationToken());
var versionNumber = searchMetadata.FirstOrDefault().Identity.Version.OriginalVersion;
return versionNumber;
}
catch (Exception ex)
{
return null;
}
}
}
public class NugetPackage
{
public string Name { get; set; }
public string Version { get; set; }
public string MinimumVersion { get; set; }
public Uri Source { get; set; }
}
}
Visual Studio credentials provider
The NuGet Client SDK solves my issue but doesn't actually answer to this SO question.
As I said, I tried to call
var componentModel = await ServiceProvider.GetGlobalServiceAsync(typeof(SComponentModel)) as IComponentModel;
componentModel.GetService<ICredentialServiceProvider>()
But this didn't work, so if anybody knows how to access the Visual Studio credentials provider, I would be really glad to know the answer.
answered Nov 9 at 9:15
Jérôme MEVEL
1,3971735
1,3971735
Great, thanks for sharing your solution here, you could Accept it as an Answer. This can be beneficial to other community members reading this thread and we could close this thread, thanks.
– Leo Liu-MSFT
yesterday
1
It solves my problem but doesn't actually fully answer my question. I started creating a sample project as suggested by Simon but I don't have much time right now. I'm also still investigating the changes made by VS to the Registry. I will mark it as accepted when all of this is done. I'm not fully satisfied with the state of my answer for the moment.
– Jérôme MEVEL
yesterday
That would be great, thank you for your contribution :).
– Leo Liu-MSFT
yesterday
add a comment |
Great, thanks for sharing your solution here, you could Accept it as an Answer. This can be beneficial to other community members reading this thread and we could close this thread, thanks.
– Leo Liu-MSFT
yesterday
1
It solves my problem but doesn't actually fully answer my question. I started creating a sample project as suggested by Simon but I don't have much time right now. I'm also still investigating the changes made by VS to the Registry. I will mark it as accepted when all of this is done. I'm not fully satisfied with the state of my answer for the moment.
– Jérôme MEVEL
yesterday
That would be great, thank you for your contribution :).
– Leo Liu-MSFT
yesterday
Great, thanks for sharing your solution here, you could Accept it as an Answer. This can be beneficial to other community members reading this thread and we could close this thread, thanks.
– Leo Liu-MSFT
yesterday
Great, thanks for sharing your solution here, you could Accept it as an Answer. This can be beneficial to other community members reading this thread and we could close this thread, thanks.
– Leo Liu-MSFT
yesterday
1
1
It solves my problem but doesn't actually fully answer my question. I started creating a sample project as suggested by Simon but I don't have much time right now. I'm also still investigating the changes made by VS to the Registry. I will mark it as accepted when all of this is done. I'm not fully satisfied with the state of my answer for the moment.
– Jérôme MEVEL
yesterday
It solves my problem but doesn't actually fully answer my question. I started creating a sample project as suggested by Simon but I don't have much time right now. I'm also still investigating the changes made by VS to the Registry. I will mark it as accepted when all of this is done. I'm not fully satisfied with the state of my answer for the moment.
– Jérôme MEVEL
yesterday
That would be great, thank you for your contribution :).
– Leo Liu-MSFT
yesterday
That would be great, thank you for your contribution :).
– Leo Liu-MSFT
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205238%2fget-nuget-credentials-stored-somewhere-by-visual-studio-in-a-vsix-project%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Why don't you use the nuget client API? github.com/NuGet/NuGet.Client that's what Visual Studio uses.
– Simon Mourier
Nov 8 at 11:21
Wow thanks a lot, honestly I'm a bit surprised the only documentation about that is an unofficial blog post from 2016. This solves my Nuget issue but I'm stubborn and I like to understand when I'm facing a problem. Do developers can officially access VS stored credentials using a service provider? If yes how can we do? Thanks for your answer
– Jérôme MEVEL
Nov 9 at 3:23
There are some drawbacks of everything being now opensourced. What's official is now a grey zone, and the documentation has been considerably reduced. We as developers are now on our own... Many VS packages are now using MEF, so I think you can ask MEF for the ICredentialServiceProvider interface defined in NuGet.PackageManagement.VisualStudio for example. If you want to get deeper, just analyze how this is implemented. Visual Studio code base is huge, good luck :-)
– Simon Mourier
Nov 9 at 7:00
That's the thing, I tried
componentModel.GetService<ICredentialServiceProvider>()
but it didn't give me any actual credential provider. Yeah it's huge and I got lost in all that code, that's why I was hoping you had the magic answer. But thanks, you helped me a lot by pointing toNuGet.Client
. With all that code, I completely got lost about what thing I was supposed to use.– Jérôme MEVEL
Nov 9 at 8:20
1
You should provide a small repro sample
– Simon Mourier
Nov 9 at 8:35