Unauthorized nuget package from Visual Studio Team Services using asp.net core rc2 - asp.net-core

I am unable to install/restore nuget packages from a Visual Studio Team Services feed in an asp.net core web application (RC2). I receive the following:
error: Response status code does not indicate success: 401
(Unauthorized).
I am running Visual Studio Community 2015 Update 2 and nuget version 3.4.4. I am able to install/restore packages from this feed in other project types.
Do I need to do something else to pass my credentials for an asp.net core web app?
Steps to reproduce:
From Team Services package tab I select "Connect to Feed" and copy the NuGet package source URL
In visual studio -> Tools -> NuGet Package Manager -> Package Manager settings -> Package sources and add the feed url from vso
Then from my ASP.NET Core Web Application (.NET Framework) project right click references -> Manage NuGet Packages
-> Select my feed from Package source (packages are listed) -> Click to install
In output:
Installing NuGet package xxxxx
Successfully installed xxxxx to WebApplication1
========== Finished ==========
Then it will try to restore the package at which point I get:
error: Response status code does not indicate success: 401 (Unauthorized).
error: Failed to retrieve information from remote source
And inside web project references - package has warning icon - NU1001 The dependency xxxxx could not be resolved

I know that it's not exactly the same issue, but people may come across this one alongside as I did.
I have installed VS Community 2019​ and yesterday I decided to remove the VS 2017, but after that, when I tried to restore the Nuget Packages made by the company, it started displaying an error of 401 Unauthorized.
After a few net searches I decided I didn't want to mess around with VS configurations and files, I then realized, since it's an 401 Unauthorized it's related with an account so what I did was:
Closed VS2019
Went to windows management credentials and removed all those that where related with my packages
Reopened VS 2019 and restored the Nuget Packages for my solution.
It them asked for my credentials, set it up and all went well from here.
Here are the two accounts I removed and got recreated:

In my case I was using an azure dev ops feed. After updating visual studio 2022 I started getting this message "Response status code does not indicate success: 401 (Unauthorized)."
I followed and tried most of the solutions here. but what worked for me was to
Go to: file -> accounts settings
Click "sign out"
Then go to the nuget manager and click the refresh button
This will then show you the azure dev ops login window where you login to your account
This worked for me, (your mileage may vary) just hope it helps someone else and saves some precious receding hairs.

I can reproduce your issue at my side and following is the workaround I use to restore the packages:
Remove the VSTS feed resource from "VS\Tools\NuGet Package Manager\Package sources".
Open "Packages" tab from your VSTS web portal.
Select the feed you want to connect and click "Connect to feed" option.
Select "Personal Access Tokens" method in the dialog.
Copy the generated command in the dialog.
Run CMD as Administrator on you machine.
Paste the copied command into CMD.
Add "-StorePasswordInClearText" argument after the command.
Run the command.
Restart the VS.
Install and restore the packages.

For me, the issue was due to incorrect credentials (not specifying the domain) when connecting to a private on-premise Azure Artifacts NuGet feed, which wasn't immediately apparent.
Using Visual Studio 2019, open NuGet Package Manager for a project. If the 'Browse' tab shows first and the package source is the private NuGet feed, there appears to be no issue as it initially lists all packages. However, switching to the 'Installed' tab results in a login dialogue popping up.
If I enter my username and password without the domain (so username intead of domain/username), it appears to accept this, but then no other versions are listed for my installed packages other than the version installed. If I go to the 'Browse' tab, I then see the following error:
When I click 'Show errors in output', I see the following:
Failed to retrieve metadata from source 'https://[domain]/[Collection]/_packaging/[GUID]/nuget/v3/query2/?q=&skip=0&take=26&prerelease=true&semVerLevel=2.0.0'.
Response status code does not indicate success: 401 (Unauthorized).
To resolve this, in Credential Manager, I close Visual Studio, then remove any credentials relating to the Azure DevOps server(e.g., [domain], VSCredentials_[domain]). I noticed that the username for these showed the wrong domain - it showed the Azure DevOps server domain instead of the Active Directory domain.
I then reopen Visual Studio, open NuGet Package Manager again and this time (on the 'Installed' tab) enter my credentials including the domain (domain/username). This resolves the issue and allows me to connect to the Azure Artifact NuGet feed.

This happens when you change your profile password. Just sign out and from top right (at your profile picture-> account settings); sign in again and your problem will be solved.

I had a similar problem (no authentication) in the NuGet Restore task of a VSTS build definition. The solution was to add a NuGet.config file in the root of the project with a reference to the official and my custom feed. Maybe it helps your core project also.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="RmlrTools" value="https://<MyProjectName>.pkgs.visualstudio.com/DefaultCollection/_packaging/<MyFeedName>/nuget/v3/index.json" />
</packageSources>
<!-- used to store credentials -->
<packageSourceCredentials />
<!-- Used to specify which one of the sources are active -->
<activePackageSource>
<!-- this tells only one given source is active -->
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
<!-- this tells that all of them are active -->
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<!-- Used to disable package sources -->
<disabledPackageSources />
<!--
Used to specify default API key associated with sources.
See: NuGet.exe help setApiKey
See: NuGet.exe help push
See: NuGet.exe help mirror
-->
<!--<apikeys>
<add key="http://MyRepo/ES/api/v2/package" value="encrypted_api_key" />
</apikeys>-->
</configuration>

Try restarting the computer before you try any of the above.

In my case , I followed these steps
create the personal access token with relevant credentials
download nuget.exe (nuget cli)
using windows run command open the cmd,then
cd C:\Downloads(where the cli is downloaded) ,type
"nuget.exe" and enter
execute -->
nuget.exe sources Add -Name "MyFeedName" -Source "https://myfeedurl" -username username -password MyAccessToken
in visual studio tools->commandline->developer command prompt
dotnet restore

Go to "Manage Nuget Packages"
Click "Setting" from right top Corner
Untick "Packages"

In my case I was using Azure Devops private feed and the NuGet package restoring worked in Visual Studio and in Nuget CLI but it didn't work with Rider and dotnet restore command
The solution was to install The Azure Artifacts Credential Provider and it fixed the problem. I just had to run this command to install it:
iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) }"
This is a fix for a local developer machine. For fixing it on CI/CD check this question.

I'm using VS 2022. The way I was able to fix it is to relog into VS. The trick is the tooltip on the top right SAYS I'm logged in, but when you click your profile logo on the top right, then goto Account Settings, it told me I needed to "reenter my credentials". How does that work, I'm logged in, but I'm not logged in? Turns out it doesn't work, I needed to log in AGAIN for it to REALLY work.

Related

asp.net core 2.1 HTTP Error 502.5

When I am trying to run my solution I am getting In the browser:
HTTP Error 502.5 - Process Failure
Debugging stops almost immediately after it starts and there is no error message inside visual studio.
In the output window this is the only message:
The program '[30700] dotnet.exe' has exited with code -2147450730 (0x80008096).
The project was working fine, I just installed a nuget package and this started happening. I tried deleting it and removing the package cache but it still happens.
Event viewer shows error with IIS Express AspNetCore Module.
Application 'MACHINE/WEBROOT/APPHOST/PROJECTNAME' with physical root 'E:\path\ProjectName\' failed to start process with commandline 'e:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\web tools\projectsystem\VSIISExeLauncher.exe -argFile "C:\Users\username\AppData\Local\Temp\tmp49E1.tmp"', ErrorCode = '0x80004005 : 0.
I am a bit lost as there is no error to go on.
Any ideas?
Well! This is due to appropriate .NET Core SDK missing problem. Your project's package versions are higher than the SDK version installed on your machine.
Download the latest version v2.1.401 (at the time of that answer) from here: Download .NET Core SDK and install it.
Now restart your computer and run the project again.
Hope your problem will be solved!
Although it was already answered, I'll post here my solution for the same problem (HTTP Error 502.5 when starting my webapp on Asp.NET CORE 2.1, error code 0x80004005) that has a different reason, as reference of another possibility.
Short Answer:
If the name of the application has a space (character) on it, the current version of Visual Studio (15.8.9) has a bug, that doesn't include quotes to make it a literal string argument on the moment of execution (through commandline) on the web.config file, generated when publishing your webapp.
Example:
web.config generated by Visual Studio (version 15.8.9 - Date: 2018-Nov-05):
[...]
<aspNetCore processPath="dotnet" arguments=".\My Web App.dll" stdoutLogEnabled=... />
[...]
web.config with correct quotation:
[...]
<aspNetCore processPath="dotnet" arguments='".\My Web App.dll"' stdoutLogEnabled=... />
[...]
You can see on the attribute arguments on the second example, that I included (manually) single quotes, making it pass the full string ".\My Web App.dll" as the argument on the moment of execution.
Detailed Answer:
Every time I update my Visual Studio for a newer SDK (and using the most recent version of Asp.net Core in my application) it give me the Http Error 502.5, IF i do not update the runtime libraries on my server too. So, obviously the first thing that I did was update the runtime libraries on the server (which always solved this problem to me), but this time it didn't worked.
So, starting to troubleshoot, I just tried to start my webapp from the command line (prompt), and it started perfectly.
So, I knew that there was something wrong with the way my webapp was being started. The starting configuration (on asp.net core) is in the web.config file.
[...]
<aspNetCore processPath="dotnet" arguments=".\My Web App.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
[...]
In Asp.net Core, the web application is started/executed from the commandline (prompt) on windows, by IIS (i'm strictly speaking of common scenario).
Till now, it always had a .exe file between the published files, that started the whole thing, and this was the file called by IIS Module through commandline.
Since Asp.net CORE 2.1 (and some minor update that i don't know exactly), there is no .exe file, and the PATH of Web App is passed by argument. So you have the command that is dotnet and a argument to this command that is specified as argument attribute, on the web.config file. (as shown in the example above)
Taking a look on my published web.config file, you can see the processPath and arguments attributes. In the previous test, I knew that dotnet was a recognized command, since I was able to start my webapp on windows command prompt. Then, looking carefully the arguments attribute, I saw that there was no (surrounding) quotation for the value, that contained space characters in it.
So in the startup of my webapp, instead the dotnet command receive the full path .\My Web App.dll, it was receiving 3 different arguments: .\My , Web , App.dll .
Since the value of the arguments attribute is passed through commandline, it has to have quotation when passed to the commandline, becoming a literal string.
So I mannualy added the necessary surrounding quotation on the arguments attribute value, in the web.config file, and my web app started to work perfectly!
To see the example of the bug, and how to correct it, just take a look on the "Short Answer" examples.
Other useful information (for Asp.net Core 2.0 and up, with Windows / IIS):
If you had a web application that was working, and is not anymore, giving the error 502.5:
It's probably a versioning problem of the runtime libraries. Your webapp is asking for newer asp.net core libraries, and your server doesn't have them yet.
Just update the runtime libraries on your server, and it should solve the problem. Download it from Microsoft (for the current version which is Asp.net Core 2.1, you can download from this link: https://www.microsoft.com/net/download/dotnet-core/2.1).
How to start your webapp manually, for better troubleshooting:
Open the windows command prompt, and try to execute the command dotnet. If it's not recognized, than you have to install (or repair) the asp.net core module and dependencies (google is your friend. Just search how to install asp.net core). Alternatively, you can check the Asp.net Core runtime libraries version with the command dotnet --version.
Once the dotnet command is recognized, you can start your webapp manually.
Navigate to the folder where is your webapp files (usually will be in inetpub, wwwroot, etc..). Then, locate the .dll file that is your application's assembly. Usually, it will have the name of your application (pretty easy, right!?). Then, execute it with the command dotnet ".\My Web App.dll".
Example:
If there is a error, you will see some useful information on the prompt window. If the webapp starts correctly, then it's some issue with the startup configuration, probably web.config file.
Another method to see more detailed information on asp.net core failure:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/troubleshoot?view=aspnetcore-2.1#application-event-log
Access the Application Event Log:
Open the Start menu, search for Event Viewer, and then select the Event Viewer app.
In Event Viewer, open the Windows Logs node.
Select Application to open the Application Event Log.
Search for errors associated with the failing app. Errors have a value of IIS AspNetCore Module or IIS Express AspNetCore Module in the
Source column.
Details of my issue:
When executing requests, the error presented was: HTTP Error 502.5 - Process Failure.
Looking on the Events Viewer (Windows Server), the information was: "Application ' ... My Web App' with physical root 'C:\ ... \ ... \' failed to start process with commandline 'dotnet .\My Web App.dll', ErrorCode = '0x80004005 : 1."
So my error code was: 0x80004005 , and the subcode was 1.
Hope it helps somebody :)

VSTS Nuget restore credentials

We are using a nuget package that requires authentication and are having issues when we try to build our project via VSTS builds. We can pull up the external nuget package feed from our authenticated browser and also via Visual Studio. The project builds locally and has no issues. However, when running through VSTS builds, we receive a 401 unauthorized messed even though we believe we have set things up properly.
Setup
Image of nuget task
Image of authentication for nuget feed
Image of personal access token that is used
Build log
Part of the log that shows that the authentication is picked up and being applied:
2018-03-30T19:38:43.2917713Z Saving NuGet.config to a temporary config file.
2018-03-30T19:38:43.3113980Z Using authentication information for the following URI: https://microsoft.pkgs.visualstudio.com/_packaging/MEE.Privacy/nuget/v3/index.json
2018-03-30T19:38:43.3123672Z [command]D:\a\_tool\NuGet\4.1.0\x64\nuget.exe sources Remove -NonInteractive -Name Privacy -ConfigFile D:\a\4\Nuget\tempNuGet_5609.config
2018-03-30T19:38:45.5301476Z Package source with Name: Privacy removed successfully.
2018-03-30T19:38:45.5348241Z [command]D:\a\_tool\NuGet\4.1.0\x64\nuget.exe sources Add -NonInteractive -Name Privacy -Source https://microsoft.pkgs.visualstudio.com/_packaging/MEE.Privacy/nuget/v3/index.json -ConfigFile D:\a\4\Nuget\tempNuGet_5609.config -Username ******** -Password ********
2018-03-30T19:38:46.0254022Z Package Source with Name: Privacy added successfully.
2018-03-30T19:38:46.0295574Z [command]D:\a\_tool\NuGet\4.1.0\x64\nuget.exe restore D:\a\4\s\msc\dev\Msc.Privacy\Msc.Privacy.sln -Verbosity Detailed -NonInteractive -ConfigFile D:\a\4\Nuget\tempNuGet_5609.config
Error that we receive when trying to find nuget package:
The nuget command failed with exit code(1) and error(Errors in packages.config projects
Unable to find version '1.1.18087.3' of package 'Microsoft.PrivacyServices.CommandFeed.Client'.
C:\Users\VssAdministrator\.nuget\packages\: Package 'Microsoft.PrivacyServices.CommandFeed.Client.1.1.18087.3' is not found on source 'C:\Users\VssAdministrator\.nuget\packages\'.
D:\a\4\Nuget\..\..\_Packages: Package 'Microsoft.PrivacyServices.CommandFeed.Client.1.1.18087.3' is not found on source 'D:\a\4\Nuget\..\..\_Packages'.
https://api.nuget.org/v3/index.json: Package 'Microsoft.PrivacyServices.CommandFeed.Client.1.1.18087.3' is not found on source 'https://api.nuget.org/v3/index.json'.
https://microsoft.pkgs.visualstudio.com/_packaging/MEE.Privacy/nuget/v3/index.json: Unable to load the service index for source https://microsoft.pkgs.visualstudio.com/_packaging/MEE.Privacy/nuget/v3/index.json.
Response status code does not indicate success: 401 (Unauthorized).
Questions
Any ideas on what we could be missing?
It turns out our personal access token was not setup properly. When creating the token, we weren't choosing the correct account. To fix our issues, we created a new token using 'All accessible [Microsoft] accounts' instead of 'myuser1'.
Image of personal access token creation

trouble publishing website TFS 2013

I have a TFS 2013 build that I'm trying to get to publish to a folder on the build server. I've installed WebDeploy, but I always get the error:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets (4274): Web deployment task failed. (Could not connect to the remote computer ("localhost"). On the remote computer, make sure that Web Deploy is installed and that the required process ("Web Management Service") is started. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_DESTINATION_NOT_REACHABLE.)
I've set up a website on the build server and that's where I'm trying to publish the website. Actually I don't even care about publishing it per se - I just need my build output to go to a folder locally automatically. Right now we have to manually open the solution and choose Publish... to get the output that subsequent InstallShield builds need for input. Here are my MSBuild arguments. Does anyone have any idea what could be missing?
/p:SrcDir=C:\Builds\TFS\WebApps\Src
/p:RevKeyname=WebAppsRevNr
/p:DeployOnBuild=true
/p:DeployTarget=MsDeployPublish
/p:MSDeployServiceURL=https://127.0.0.1:8172/msdeploy.axd
/p:CreatePackageOnPublish=True
/p:DeployIisAppPath="WebApp"
/p:MsDeployPublishMethod=WMSVC
/p:AllowUntrustedCertificate=True
/p:AutoParameterizationWebConfigConnectionStrings=False
/p:Authtype=NTLM /p:username=""
I've checked both net start wmsvc and net start msdepsvc and both are running. Any ideas?
Thanks!
UPDATE
I've tried everything that Andy suggested and now when I run this from the command line I get this bizarre error message:
"C:\Workspace\VS2013\WebApps\Main\Src\webapps.sln" (default target) (1) ->
"C:\Workspace\VS2013\WebApps\Main\Src\CoreWebApps\CoreWebApps.csproj"
(default
target) (7) ->
(AutoParameterizationWebConfigConnectionStringsCore target) ->
C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web
.Publishing.targets(2295,5): error : Could not open Source file: Could not
find
a part of the path
'C:\Workspace\VS2013\WebApps\Main\Src\CoreWebApps\Areas\Adm
in\Views\Web.config;Areas\Admin\Views\Web.config'.
[C:\Workspace\VS2013\WebApps
\Main\Src\CoreWebApps\CoreWebApps.csproj]
Any idea why it's looking for Web.config;Areas\Admin\Views\Web.config'.? That makes no sense.
Please try below items to narrow down the issue:
Try to use IP or Machine Name instead of "localhost"
Logon your build agent machine, then manually execute the same
MSBuild command within the same arguments(which you provided in build
definition) to build and deploy your solution, then check result. You
need to ensure you can manually run the same MSBuild command within
deploy argument to build and deploy your solution successfully from
build agent machine. Then use the same deploy arguments in TFS Build
definition.
Double check Web Deploy settings to make sure that the name of the
website is exactly that of what's in IIS.
Install Web Management Tools before Web
Deploy : Install the Web Management Services (Roles -> Web Server >
Management Tools > Management Services). Then uninstall Web Deploy, and then install Web Deploy again.
You can also reference this thread for your troubleshooting.
Update:
For the issue "Could not open Source file: Could not find a part of the path" you can reference below similar articles for the troubleshooting.
https://social.msdn.microsoft.com/Forums/en-US/8f959964-c951-4f9a-8486-8283a925c9f6/build-error-could-not-open-source-file-though-i-know-it-exists?forum=windowsazurewebsitespreview
https://our.umbraco.org/forum/getting-started/installing-umbraco/60222-Umbraco-721-Build-fails-after-deploy-to-Azure-WebSite (See the last two answers)

MSDeploy, IIS 6, Is the Deploy context menu available

When using IIS6, should the 'Deploy' context menu item be available when right clicking on a web site?
I've installed the Web Deploy 2.1 (web installation tool) and rebooted but still it doesn't show. Maybe it doesn't show, and you just use the Web Deploy command line instead?
Any information appreciated.
No, The "deploy" context menu is only available in IIS 7 and 7.5. You'll have to do things via command line.
If you want to migrate from iis6 to iis7 you can follow the instructions here: http://learn.iis.net/page.aspx/427/migrate-a-web-site-from-iis-60-to-iis-7/ Note part 3 which goes into the actual web deploy commands.
Part 3 – Migrate your site to the
target by using a package file
Always make a backup of the destination server. Even if you are
just testing, it allows you to easily
restore the state of your server.
%windir%\system32\inetsrv\appcmd add backup “PreWebDeploy”
Run the following command on the source server to create a package
(compressed) file of the server:
msdeploy -verb:sync -source:metakey=lm/w3svc/1 -dest:package=c:\Site1.zip > WebDeployPackage.log
Copy the package file to the destination server.
Run the following command on the destination server to validate what
would happen if a sync operation were
run:
msdeploy -verb:sync -source:package=c:\Site1.zip -dest:metakey=lm/w3svc/1 -whatif > WebDeploySync.log
After verifying the output, run the same command again without the whatif
flag:
msdeploy -verb:sync -source:package=c:\Site1.zip -dest:metakey=lm/w3svc/1 > WebDeploySync.log

Signing assemblies with PFX files in MSBuild, Team Build, and TFS

I get this error when trying to build a project using Team Build (MSBuild) on TFS 2010:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (1970):
Cannot import the following key file: CCC.pfx.
The key file may be password protected.
To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_C00C673BBB353901
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (1970):
Importing key file "CCC.pfx" was canceled.
It all builds OK in Visual Studio 2010. The assembly is signed with a PFX file. Usually in Visual Studio we are prompted for the password the first time we build, but then never again...
I've tried running:
sn -i companyname.pfx VS_KEY_3E185446540E7F7A
as other replies as suggested in Stack Overflow question Cannot import the keyfile 'blah.pfx' - error 'The keyfile may be password protected'. I've tried importing into the personal certificate store as suggested in Stack Overflow question Using MSBuild to sign ClickOnce or assembly results in error MSB3321. But all to no avail, still the same error.
How do I do it? Do I have to somehow add the certificate to the Windows account the build service runs under or something like that?
Alternatively, how do I make the build done in Team Build not use signing? I just want to check it compiles and run the unit tests. I don't need signing for that.
You need to adapt this answer to your specific. Something like:
sn -i companyname.pfx VS_KEY_C00C673BBB353901
What I did is not that elegant, but works: log in as the user that runs msbuild on the build machine, manually invoke msbuild, and then type in the password when prompted. It'll now be saved in that user's certificate store, and now the builds can run unattended.
What finally fixed it for me was making the account under which TFS Build service runs an administrator on the local machine.
Don't know though if any of the other stuff I was trying before also needs to be done to get it working. But before it was admin it didn't work after it became admin it worked.
I was getting the same error, and after reading your "administrator" comment - I just ran VS Command Prompt as Admin and it now works fine.
I have faced similar issue
Scenario 1: While building project in local system
In my case i was getting the manifest signing error once i download the project from TFS and build it.
To avoid this issue I right clicked on the project ==> Properties ==> Signing
then unchecked "Sign the ClickOnce Manifests"
OR
You can click Select from store button and select your login id from the dialog box open.
OR
You can install the PFX file manually and later click on More Options button to install those certificate.
Scenario 2:- Manifest error during Build
Here to resolve this error i first clicked Select from store button and select my login id from the dialog box .Then I committed that project in TFS first and then run the build.
I had following settings:
<PropertyGroup>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>MyKey.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
Assembly signing was turned off, but AssemblyOriginatorKeyFile caused error during manifest sign. Removed AssemblyOriginatorKeyFile to fix it.