VSO Build not able to download packages - nuget

I have the following nuget.config file and bellow is the file content
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="Packages" />
</config>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<packageSources>
<!-- Ditch all the Global NuGet package sources we only want a
single private NuGet repo for this project -->
<clear />
<add key="private="private" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
<disabledPackageSources>
<add key="nuget.org" value="false" />
</disabledPackageSources>
</configuration>
All the packages which exist in the private feed are restored but the same is not happening with the ones in nuget.org:
From VSO build output
Feeds used:
C:\Users\buildguest\AppData\Local\NuGet\Cache
private
https://www.nuget.org/api/v2/
...
Restoring NuGet package AutoMapper.5.2.0.
WARNING: Unable to find version '5.2.0' of package 'AutoMapper'.
This is happening during the NuGet restore step in VSO.

Use NuGet.Protocol.Core.v3 feed protocol with
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
instead of
<add key="nuget.org" value="https://nuget.org/api/v2/" />

enter image description here
Inside Nuget.config put the bellow code.
<configuration>
<packageRestore>
<add key="enabled" value="True"/>
<add key="automatic" value="True"/>
</packageRestore>
</configuration>

Related

Why can't Visual Studio restore NuGet packages from Azure DevOps artifact feed

I am setting up Visual Studio 2022 Community Edition on a new workstation. I have instructions for connecting to an Azure DevOps artifact feed that worked on my previous workstations. Despite following the same instructions, I can't restore NuGet packages from the Azure DevOps artifact feed.
I configure the artifact feed manually by editing %APPDATA\NuGet.config and adding an element to the packageSources element just below the entry for nuget.org.
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="azure-devops-feed" value="https://pkgs.dev.azure.com/xxxxxxxxxxxxxx/_packaging/xxxxxxxxxxxxxx-feed/nuget/v3/index.json" protocolVersion="3" />
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
Note the protocolVersion="3" on the new element; this is needed because Visual Studio 2022 was using protocol version 2 which is not supported by the artifact feed.
When I try to run the build, I get the output
NU1301: Unable to load the service index for source https://pkgs.dev.azure.com/xxxxxxxxxxxxxx/_packaging/xxxxxxxxxxxxxx-feed/nuget/v3/index.json.
I opened https://pkgs.dev.azure.com/xxxxxxxxxxxxxx/_packaging/xxxxxxxxxxxxxx-feed/nuget/v3/index.json in an Incognito tab in my browser to verify that, once I authenticated using the same Windows account that I use to log in to Visual Studio, the index.json is accessible and contains the expected contents.
Update
This was solved by copying the NuGet.config file from my old workstation. The only difference is that the protocolVersion="3" attribute was removed from the private feed element. When I was setting this up previously I had to add that attribute, as otherwise Visual Studio used Protocol Version 2 which got 404 errors.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="azure-devops-feed" value="https://pkgs.dev.azure.com/xxxxxxxxxxxxxx/_packaging/xxxxxxxxxxxxxx-feed/nuget/v3/index.json" />
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
</packageSources>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
<packageManagement>
<add key="format" value="0" />
<add key="disabled" value="False" />
</packageManagement>
</configuration>
NU1301: Unable to load the service index for source https://pkgs.dev.azure.com/xxxxxxxxxxxxxx/_packaging/xxxxxxxxxxxxxx-feed/nuget/v3/index.json.
The cause of the issue is that the Private Nuget source miss Credentials in Nuget.config file.
To solve this issue, you can use the following command to add the Credentials to the Nuget.config file.
nuget sources update -name azure-devops-feed -username 123 -password <PAT>
Then you can check if the Nuget.config file has added the Credentials.
For example:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
<add key="test1" value="https://pkgs.dev.azure.com/xx/xx/_packaging/xx/nuget/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<test1>
<add key="Username" value="123" />
<add key="Password" value="based64PAT" />
</test1>
</packageSourceCredentials>
</configuration>
For more detailed info, you can refer to this doc: packageSourceCredentials

Local copy of nuget.exe unable to find any packages on nuget.org

I've been using this SO answer and this Powershell script to transform .NET config files.
The gist of the script is that it downloads a local version of nuget.exe, then uses this to download NuGet packages which will be used for the XDT transformations.
My problem is that when it invokes a line to download a NuGet package I'm told that the package cannot be found. For example...
Unable to find version '3.1.0' of package 'Microsoft.Web.Xdt'.
...even though nuget.org clearly states that this is valid - link. I've tried it with other packages and their publicly-stated versions, and receive the same message.
Another point to be aware of is that we have our own private NuGet feed. When I run the Powershell script it will also attempt to search that feed, which I don't want it to do, so I have added a nuget.config file in the same directory as the Powershell script (I've also tried it in the same directory as the local nuget.exe) in which I have disabled our custom NuGet source...
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<disabledPackageSources>
<add key="DevOps" value="true" />
</disabledPackageSources>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
<packageManagement>
<add key="format" value="0" />
<add key="disabled" value="False" />
</packageManagement>
</configuration>
Other than that <disabledPackageSources /> section the rest of this nuget.config was copied from my machine-level nuget.config.
Can anyone explain why this local instance of nuget.exe is unable to find any packages from nuget.org?

IIS 10 - web.config - how to enable default document without script access

We have a folder which contains only static html and images etc. No scripts should be allowed to execute from within this folder. However we would still like to be able to use html default documents.
What is the correct way to configure this?
This is the web.config file...
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers accessPolicy="Read"/>
<defaultDocument enabled="true">
<files>
<clear />
<add value="default.html" />
<add value="default.htm" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
If I attempt to access http://mysite/mystaticfolder/ it fails with the error...
HTTP Error 403.1 - Forbidden
However the URL http://mysite/mystaticfolder/default.html works fine.
Surely it shouldn't be nescessary to allow dynamic scripts, just to be able to serve static html default documents?
In case it helps anyone, I've been able to solve it with the following...
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers accessPolicy="Read">
<clear/>
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule" resourceType="Either" requireAccess="Read" />
</handlers>
<defaultDocument enabled="true">
<files>
<clear />
<add value="default.html" />
<add value="default.htm" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
I'm not entirely sure though why this doesn't work by default though.

How do I uninstall a nuget package that is not available?

I have moved my project to a new machine and do not have access to an old nuget package called SBD.Common that was stored locally on the old machine.
I want to uninstall the package from the project
When I use Manage Nuget Packages for solution I can see that the package is installed but not available in this source.
When I click the Uninstall button I get an error
An error occured while trying to restore the packages" Unable to find version '1.0.0' of 'SBD.Common'
c:\Program files(x86)\Microsoft SDKS\NugetPackages\:Package 'SBD.Common.1.0.0' is not found on source 'C:\Program Files(x86)\Microsoft SDKs\NuGetPackages\'
https://api.nuget.org/v3/index.json:Package 'SBD.Common.1.0.0' is not found
How do I tell my project that I don't want to restore this package without gaining access to the package?
Here is my Nuget.Config at C:\Users\MyName\AppData\Roaming\NuGet
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<disabledPackageSources>
<add key="Microsoft and .NET" value="true" />
</disabledPackageSources>
<packageRestore>
<add key="enabled" value="False" />
<add key="automatic" value="False" />
</packageRestore>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
</configuration>
I am using Nuget version 3.4.4.1321
the problem was that I had the files listed in packages.config

Nuget Package Manager combining local and external servers

Hoping for a little help here. I've a custom built dll which has a dependency on EntityFramework. I've deployed the custom build dll to our local nuget server. However I have not deployed EntityFramework. That is available on the external nugget servers.
When I attempt to install my custom build dll using the Nuget Solution Manager, I get the following error:
Attempting to resolve dependencies for package 'CustomBuilt.dll.2016.10.10.6' with DependencyBehavior 'Lowest'
Unable to resolve dependency 'EntityFramework.dll'. Source(s) used: 'LocalServer', 'NugetAlt1', 'NugetAltHttps', 'nuget.org', 'Microsoft and .NET'.
The url's for external Servers are:
NugetAlt1: http://packages.nuget.org/v1/FeedService.svc/
NugetAltHttps: https://www.nuget.org/api/v2/
nuget.org: https://api.nuget.org/v3/index.json
Microsoft and .Net: https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/
I am using VS2015. I've also tried with VS2013.
Also I've added a nuget.config file to the solution. Still getting the error:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="LocalServer" value="http://localserver:8089/nuget" />
<add key="NugetAlt1" value="http://packages.nuget.org/v1/FeedService.svc/" />
<add key="NugetAltHttps" value="https://www.nuget.org/api/v2/" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
</configuration>
Any thoughts/ideas?
Kind Regards,
Fiona
I finally found it.. The problem was in the nuspec file that I was using to generate the package. The id of my dependencies was incorrect.
I specified the following:
<dependencies>
<dependency id = "EntityFramework.dll" version = "6.0.0.0" />
</dependencies>
This is incorrect. The package name of EF is EntityFramework not EntityFramework.dll
This is how it should be specified:
<dependencies>
<dependency id = "EntityFramework" version = "6.0.0.0" />
</dependencies>