23

I have a web app in dot net along with other projects. when i open the .sln file and publish the web project, it does. But, when I try to publish the web proj using command line and .csproj, it gives an error. "Nothing to do. None of the projects specified contain packages to restore."

Dharman
  • 30,962
  • 25
  • 85
  • 135
Suleman Mehmood
  • 391
  • 1
  • 5
  • 14
  • 2
    Did you ever find a solution to this? – Franco Pettigrosso Nov 06 '19 at 14:36
  • Yes, first I was using dotnet pusblish. the issue was resolved using msbuild – Suleman Mehmood Nov 14 '19 at 11:51
  • 2
    how was it resolved using msbuild? I just upgraded nuget, and followed this: https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore#migrate-to-automatic-package-restore-visual-studio and now my msbuild is failing - says nothing to restore! – Daniel Williams Dec 30 '19 at 23:08
  • 2
    @DanielWilliams did you resolve this? – thatOneGuy Jan 08 '20 at 12:57
  • 1
    @SulemanMehmood can you please post the solution? – Nishant May 27 '20 at 08:12
  • @Nishant Please use msbuild to build the web projects using command line. it will fix the issue – Suleman Mehmood Jun 05 '20 at 07:46
  • 5
    If you use msbuild.exe -t:restore, you need to change to pakage reference in order for that to work (and not say "nothing to restore"). In Visual Studio, go to Tools->Options->NuGet package manager -> General. Change package management to PackageReference and then remove all your Nuget dependencies and re-add them. This will modify your .proj files and then -t:restore will work. – kernelony Dec 02 '20 at 15:15
  • 3
    @kernelony or you can use the `-p:RestorePackagesConfig=true` switch as noted [here](https://stackoverflow.com/a/65209365/682203) – Angel Yordanov May 30 '21 at 15:51
  • @Nishant Can you please post the solution for this, thank you – GuidoG Aug 19 '22 at 12:46

2 Answers2

3

I had this problem in a batch file I use to build a UWP component for release. The build command is

%MSBUILD% CartoType\src\main\single_library\uwp\CartoType\CartoType.sln -p:Configuration=Release;Platform=x64

where %MSBUILD% is the full path to msbuild. I first added an msbuild command with the -t:restore option and got the message reported by the original poster ('Nothing to do. None of the projects specified contain packages to restore').

The solution was to add this command before the command given above:

%MSBUILD% CartoType\src\main\single_library\uwp\CartoType\CartoType.sln -p:RestorePackagesConfig=true -t:restore
Graham Asher
  • 1,648
  • 1
  • 24
  • 34
  • thank you, this worked for me. `msbuild .\mysln.sln /p:RestorePackagesConfig=true /t:Restore /p:Configuration=Release;Platform="Any CPU"` – Josh Johanning Oct 31 '22 at 15:25
1

I got this after converting my csproj to vs2019 format and running dotnet test. The solution was to ensure i had the right test adapter and framework. My csproj files had both the old Microsoft.VisualStudio.QualityTools.UnitTestFramework reference and the new MSTest.TestAdapter + MSTest.TestFramework + Microsoft.NET.Test.Sdk. I kept the new ones and my tests were run.

Lars Pellarin
  • 606
  • 6
  • 10