azure devops dotnet core app : why "dotnet restore" job fails?

I have an azure pipeline for a dotnet core app, and when it executes this job , i got:

2023-02-16T17:02:26.7325011Z      1>C:\hostedtoolcache\windows\dotnet\sdk\6.0.406\NuGet.targets(132,5): error : '6.1.6,6.2.3' is not a valid version string. [D:\a\1\s\WebApp\WebApp.csproj]
2023-02-16T17:02:26.7944327Z          System.ArgumentException: '6.1.6,6.2.3' is not a valid version string.
2023-02-16T17:02:26.7945294Z             at NuGet.Versioning.VersionRange.Parse(String value, Boolean allowFloating)
2023-02-16T17:02:26.7946303Z             at NuGet.Versioning.VersionRange.Parse(String value)
2023-02-16T17:02:26.7947172Z             at NuGet.Commands.MSBuildRestoreUtility.AddPackageReferences(PackageSpec spec, IEnumerable`1 items, Boolean isCpvmEnabled)
2023-02-16T17:02:26.7948010Z             at NuGet.Commands.MSBuildRestoreUtility.GetPackageSpec(IEnumerable`1 items)
2023-02-16T17:02:26.7948973Z             at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
2023-02-16T17:02:26.7949761Z             at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
2023-02-16T17:02:26.7950412Z             at NuGet.Commands.MSBuildRestoreUtility.GetDependencySpec(IEnumerable`1 items)
2023-02-16T17:02:26.7951037Z             at NuGet.Build.Tasks.RestoreTask.ExecuteAsync(ILogger log)
2023-02-16T17:02:26.7951399Z        Done executing task "RestoreTask" -- FAILED.
2023-02-16T17:02:26.7951774Z      1>Done building target "Restore" in project "WebApp.csproj" -- FAILED.
2023-02-16T17:02:26.7961752Z      1>Done Building Project "D:\a\1\s\WebApp\WebApp.csproj" (Restore target(s)) -- FAILED.
2023-02-16T17:02:26.8026122Z Build FAILED.
2023-02-16T17:02:26.8030306Z        "D:\a\1\s\WebApp\WebApp.csproj" (Restore target) (1) ->
2023-02-16T17:02:26.8030690Z        (Restore target) -> 
2023-02-16T17:02:26.8031149Z          C:\hostedtoolcache\windows\dotnet\sdk\6.0.406\NuGet.targets(132,5): error : '6.1.6,6.2.3' is not a valid version string. [D:\a\1\s\WebApp\WebApp.csproj]
2023-02-16T17:02:26.8031674Z     0 Warning(s)
2023-02-16T17:02:26.8031958Z     1 Error(s)
2023-02-16T17:02:26.8034195Z Time Elapsed 00:00:00.91
2023-02-16T17:02:26.8611133Z ##[error]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1
2023-02-16T17:02:26.8625609Z ##[error]Packages failed to restore
2023-02-16T17:02:26.8631699Z Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: and . To learn about more such changes and troubleshoot, refer here:
2023-02-16T17:02:26.8710382Z ##[section]Finishing: Restore Nuget Packages

I am unable to figure out why, any help please ?

>Solution :

In your error you can see it says

System.ArgumentException: '6.1.6,6.2.3' is not a valid version string.

And indeed your problem is actually in this file:

where you have that invalid Version string in your package reference:

<PackageReference Include="System.Management.Automation" Version="6.1.6,6.2.3" />

Leave a Reply