Open jklawrence opened 2 years ago
I could repro with the following steps: 1.Create a non-SDK project. E.g. ClassLibrary (.NETFramework) 2.Install Newtonsoft.json package on this project 3.Go to the solution folder, clear all the contents in folder "packages" 4.Edit the user-wide NuGet.Config file, remove nuget.org source. Make sure there is no other NuGet.Config file in the path contains nuget.org source. 5.Run command
msbuild .\ClassLibrary2\ClassLibrary2.sln -t:restore -p:RestorePackagesConfig=true -p:RestoreSources=https://api.nuget.org/v3/index.json -v:n
The output is:
Build FAILED.
"C:\Repos\ClassLibrary2\ClassLibrary2.sln" (Restore target) (1) ->
(Restore target) ->
C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(130,5): warning : Unable to find version '13.0.1' of package 'Newtonsoft.Json'. [C:\Repos\ClassLibrary
2\ClassLibrary2.sln]
C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(130,5): warning : C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Newtonsoft.Json.13.0.1' is not found on
source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'. [C:\Users\henli\Source\Repos\ClassLibrary2\ClassLibrary2.sln]
C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(130,5): warning : [C:\Repos\ClassLibrary2\ClassLibrary2.sln]
C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(130,5): warning : Unable to find version '13.0.1' of package 'Newtonsoft.Json'. [C:\Users\henli\Source\Repos\ClassLibrary
2\ClassLibrary2.sln]
C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(130,5): warning : C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'Newtonsoft.Json.13.0.1' is not found on
source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'. [C:\Users\henli\Source\Repos\ClassLibrary2\ClassLibrary2.sln]
C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(130,5): warning : [C:\Repos\ClassLibrary2\ClassLibrary2.sln]
"C:\Repos\ClassLibrary2\ClassLibrary2.sln" (Restore target) (1) ->
(Restore target) ->
C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(130,5): error MSB4181: The "RestoreTask" task returned false but did not log an error. [C:\Users\henli\Source\Repos\Class
Library2\ClassLibrary2.sln]
2 Warning(s)
1 Error(s)
While compared to an SDK project, the property RestoreSources
works:
1.Create an SDK project. E.g. ClassLibrary (.NET Core)
2.Install Newtonsoft.json package on this project
3.Go to the global package folder, delete newtonsoft.json folder.
4.Edit the user-wide NuGet.Config file, remove nuget.org source. Make sure there is no other NuGet.Config file in the path contains nuget.org source.
5.Run command
msbuild .\ClassLibrary3\ClassLibrary3.sln -t:restore -p:RestoreSources=https://api.nuget.org/v3/index.json -v:n
The restore is successful.
Note to the implementer: Enabling RestoreSources
in packages.config restore might lead to a discrepancy in VS vs MSBUild restore for the given project.
Ex. Imagine you put RestoreSources in the project file, that wouldn't be respected in VS (not saying it should).
I had to use this workaround to get my few packages.config-based projects to build with the same pipeline:
Added a nuget.config file to the solution:
<configuration>
<packageSources>
<add key="MyFeed" value="https://MyURL/nuget/v3/index.json" />
</packageSources>
</configuration>
NuGet Product Used
MSBuild.exe
Product Version
16.11.1+3e40a09f8 for .NET Framework
Worked before?
Unsure
Impact
It's more difficult to complete my work
Repro Steps & Context
msbuild Example.sln -t:restore -p:RestorePackagesConfig=true -p:RestoreSources=${CustomSource}
What I expected: Packages to restore successfully.
What I got: A warning saying the package could not be found on the default source of 'https://api.nuget.org/v3/index.json'
Nuget.exe restore of packages.config with the
-Sources
flag works fine. MSBuild restore of PackageReferences using the RestoreSources parameter works fine.Verbose Logs