Skip to content

Unable to use feed views to restore NuGet packages due to missing character encoding in NuGetXmlHelper #437

@marchie

Description

@marchie

Hello!

I'm trying to use the DotNetCoreCLI@2 task to restore NuGet packages from the @Release view on a private Azure DevOps Artifacts feed.

I have configured the task as follows:

    - task: DotNetCoreCLI@2
      displayName: '.NET restore'
      inputs:
        command: 'restore'
        restoreArguments: '--locked-mode'
        projects: '**/*.csproj'
        feedsToUse: 'select'
        includeNuGetOrg: false
        vstsFeed: 'MyAzureDevOpsProject/MyFeed@Release'

However, when the tasks runs, it fails:

Build FAILED.

 "/__w/1/s/MyProject.csproj" (Restore target) (1) ->
 "/__w/1/s/MyProject.csproj" (_GenerateRestoreGraphProjectEntry target) (1:5) ->
 (_GetRestoreSettings target) -> 
 /usr/share/dotnet/sdk/8.0.406/NuGet.targets(745,5): error : NuGet.Config is not valid XML. Path: '/__w/1/Nuget/tempNuGet_10029.config' [/__w/1/s/MyProject.csproj]
  /usr/share/dotnet/sdk/8.0.406/NuGet.targets(745,5): error :   The '@' character, hexadecimal value 0x40, cannot be included in a name. Line 1, position 252. [/__w/1/s/MyProject.csproj]

 0 Warning(s)
 1 Error(s)

I believe this is due to an issue with the temporary nuget.config file that is being generated by the NuGetConfigHelper from within this repo.

When the source is added to the temporary nuget.config file, the "feed name" is used as the package source key. When we're using a feed view, the feed name will contain the @ character - e.g. MyFeed@Release - and this is an invalid XML node name. The @ character needs to be encoded, so the example above would become MyFeed_x0040_Release.

(See the "Test Source" example in the nuget.config documentation for an example of this encoding.)

I believe if the @ character is added to the array of characters that should be encoded here, the issue will be resolved.

Can this be added so that it is possible to use a "feed view" to restore NuGet packages?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions