简体   繁体   中英

.NET Core NuGet restore fails with private NuGet feed (VSTS CI Build)

This issue is regarding the continuous integration feature in visual studio team services, specifically in automated builds.

I've set up a build definition to build my .net core mvc application.

It is using .NET core v1 and compiling against .net framework 4.5.2.

I've followed the instructions here:

https://www.visualstudio.com/en-us/docs/build/apps/aspnet/ci/build-aspnet-core

I have a private NuGet feed set up in VSTS Here is the command that adds the package feed source:

Sources Add -Name "CiiDLFeed" -UserName "<username>" -Password "<password>" -ConfigFile $(Build.SourcesDirectory)/Nuget.config -Source https://mycompany.pkgs.visualstudio.com/_packaging/DLFeed/nuget/v3/index.json

The error I'm receiving:

error: Unable to load the service index for source https://mycompany.pkgs.visualstudio.com/_packaging/DLFeed/nuget/v3/index.json . error: Password decryption is not supported on .NET Core for this platform. The following feed uses an encrypted password: 'CiiDLFeed'. You can use a clear text password as a workaround.

In response to this, I added "-StorePasswordInClearText" parameter to the NuGet source add command:

Sources Add -Name "CiiDLFeed" -UserName "<username>" -Password "<password>" -ConfigFile $(Build.SourcesDirectory)/Nuget.config -Source https://mycompany.pkgs.visualstudio.com/_packaging/DLFeed/nuget/v3/index.json -StorePasswordInClearText

Now, I get a 401 error:

error: Unable to load the service index for source https://mycompany.pkgs.visualstudio.com/_packaging/DLFeed/nuget/v3/index.json . error: Response status code does not indicate success: 401 (Unauthorized).

I'm using the same exact credentials that work correctly in a separate build definition, accessing the same nuget feed (a .NET web forms app), so it should not be giving me a 401.

I've also tried simply referencing the library dll's instead of NuGet packages in a private feed, but that appears to be not possible with .NET Core:

.NET core projects only support referencing .NET framework assemblies in this release. To reference other assemblies, they need to be included in a NuGet package and reference that package.

The workaround solution we used is to setup a local NuGet source that is a directory in the project. Then add your .nupkg files to it, and reference them in your project.

This allows the VSTS CI build to access your NuGet package without setting up a remote NuGet source.

eg:

project_directory/
    ... project files ...
    my_nuget_repo/
        mypackage.nupkg

Add the local source:

nuget sources add -Name "my_nuget_repo" -Source "<path_to_project>/my_nuget_repo"

You need to your own Nuget.Config file instead (Can use PAT as password):

  1. Add Nuget.Config file (include the corresponding packageSource) to source control
  2. Edit your build definition
  3. Remove/disable Command line step that used to add package source
  4. Select .Net Core (Preview) Restore step.

arguments like:

--configfile $(build.sourcesdirectory)/ConsoleAppCore/Nuget.Config

Note: You can create or edit a NuGet.config at the solution root, next to the project.json file and check into source control, with this way, you don't need to specify configfile argument for .Net Core restore step.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM