Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WARNING: Error reading msbuild project information, ensure that your input solution or project file is valid. NETCore and UAP projects will be skipped, only packages.config files will be restored. #9411

Closed
rrelyea opened this issue Apr 8, 2020 · 8 comments

Comments

@rrelyea
Copy link
Contributor

rrelyea commented Apr 8, 2020

In NuGet 4.7 and later, we started loading msbuild project files in a faster way. This faster way had the side effect of not being forgiving when loading msbuild project files that have includes to .props/.targets files that don't exist when being evaluated.

when running "nuget.exe restore foo.sln"
you may see: WARNING: Error reading msbuild project information, ensure that your input solution or project file is valid. NETCore and UAP projects will be skipped, only packages.config files will be restored.

The best way to fix this is to hunt down the problems in your projects.

my technique in command prompt if you are in the solution directory:

dir *.csproj /s/b > projects.txt
for /f %1 in (projects.txt) do nuget restore %1 [PlusOtherArgsYouNeed]

read through the output to see which project have restore errors and fix those projects.

a workaround to this, which you shouldn't use long term (!!!!):
set RestoreUseSkipNonexistentTargets to false in a project or via envvar:
see https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#restore-target

@rrelyea
Copy link
Contributor Author

rrelyea commented Apr 8, 2020

@nkolev92 - feel free to edit my first post above for any corrections necessary.

@rrelyea rrelyea closed this as completed Apr 8, 2020
@vdevappa
Copy link

vdevappa commented Apr 9, 2020

Do you think doing this will resolve my issue?

https://developercommunity.visualstudio.com/content/problem/981107/service-fabric-build-failing-with-error-microsoftp.html

If so, I did try running this command, but from cmd or visual studio command prompt both, the nuget command is not recognized. How do I run this?

@vdevappa
Copy link

vdevappa commented Apr 9, 2020

Answering my own question:

"Install the nuget.exe CLI by downloading it from nuget.org, saving that .exe file to a suitable folder, and adding that folder to your PATH environment variable."

https://docs.microsoft.com/en-us/nuget/consume-packages/install-use-packages-nuget-cli

It only worked for me after specifying the packages folder using:

dir *.csproj /s/b > projects.txt
for /f %1 in (projects.txt) do nuget restore %1 -PackagesDirectory "C:<solution-folder>\packages"

@rrelyea
Copy link
Contributor Author

rrelyea commented Apr 14, 2020

It only worked for me after specifying the packages folder using:

dir *.csproj /s/b > projects.txt
for /f %1 in (projects.txt) do nuget restore %1 -PackagesDirectory "C:\packages"

To help others...
I added [PlusOtherArgsYouNeed] to the first post

@ignotus87
Copy link

I share the solution to my case, maybe it'll help someone.
Neither the workaround nor checking the errors in the nuget restore output helped my issue which occured only during an Azure DevOps Server pipeline build. After cleaning the agent's working folder, I found a new warning message in the log of the NuGet Restore task, and found out that the build was breaking due to a wrong value set to a pipeline variable named PackageVersion.

@vladsusidko
Copy link

I have the similar problem as @ignotus87, but I use github actions instead. Approximately 1 of the 10 workflow runs fails because of the identical warning produced by nuget restore command, after which build with command msbuild -m -p:Configuration=Release -t:Rebuild fails. It's hard to catch the error because it's not consistent, I can't even reproduce it locally. I would appreciate any advices or help.

@zivkan
Copy link
Member

zivkan commented Oct 13, 2023

If none of your projects have packages.config, if you're only using PackageReference, there's no good reason to use nuget restore, use msbuild -t:restore instead.

Since approx VS 16.4 from memory, if you have at least 1 packages.config, use msbuild -t:restore -p:RestorePackagesConfig=true. If you look up the property in the docs, it'll tell you exactly which version of VS it was added to.

Anyone building their solution with dotnet build should use dotnet restore instead, although dotnet build will auto-restore, unless you use dotnet build --no-restore. Unless your CI build step has that --no-restore, don't restore in a separate step, as it's just slowing down the build for no reason.

@vladsusidko
Copy link

@zivkan Thanks for your reply! I replaced nuget restore with msbuild -t:restore -p:RestorePackagesConfig=true and it works just fine. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants