Project references NuGet package(s) that are missing on this computer - c#

This morning I received the following error when trying to build my Visual Studio ASP.NET solution:
This project references NuGet package(s) that are missing on this
computer. Use NuGet Package Restore to download them. For more
information, see http://go.microsoft.com/fwlink/?LinkID=322105. The
missing file is
..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props.
I performed a NuGet Package Restore as instructed but the results stated that: all packages are already installed and there is nothing to restore.
The NuGet Package Manager settings are as follows:
NuGet Package Settings
How can I solve this issue?

Related

Why does dotnet build on a .NET Framework 4.5 project throw "This project references NuGet package(s) that are missing"?

The sample NotepadAndCalculatorTest project built in VS Code using the terminal command dotnet build throws the following errors:
C:\Program Files\dotnet\sdk\5.0.401\Microsoft.Common.CurrentVersion.targets(820,5): error : The BaseOutputPath/OutputPath property is not set for project 'NotepadCalculatorTest.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='AnyCPU'. You may be seeing this message because you are trying to build a project without a solution file,
and have specified a non-default Configuration or Platform that doesn't exist for this project. [C:\Users\<username>\VSCode Projects\WinAppDriverTryout\Test\Samples\C#\NotepadAndCalculatorTest\NotepadCalculatorTest.csproj]
Or:
NotepadCalculatorTest.csproj(109,5): error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props.
Could someone point me towards a possible way to get rid of the errors?
dotnet build carries out an implicit restore as part of the command.
This uses dotnet restore which does not support project references in packages.config & is exactly what this project is using.
dotnet restore only supports .csproj package references.
That's why, this project builds perfectly fine in Visual Studio but dotnet build throws errors.
You can migrate packages.config to package references by right-clicking on the file within Visual Stduio and clicking migrate, however that still won't fix your problem as dotnet cli works properly with .NET Framework only if the project was created using the dotnet new command.
I assume this project was created in Visual Studio since it has a Visual Studio solution file - .sln - and so commonly have a differently structured .csproj format.
This then usually breaks some CLI commands, even if you migrate the references in this case.
You have 2 workarounds.
1. Use nuget restore
The easiest option is to download the NuGet CLI executable from here, taken from the downloads page.
If you are not on Windows, use this guide by Microsoft.
Add it to your PATH or place it in the root folder of the project.
Run nuget restore, which is compatible with packages.config (run .\nuget restore if you're inside PowerShell to trust the command as PowerShell does not does not load commands from the current location by default for security).
Your should get output similar to this:
PS C:\Users\StackOverflow\NotepadAndCalculatorTest> .\nuget restore
MSBuild auto-detection: using msbuild version '16.9.0.16703' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin'.
Restoring NuGet package Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview.
Restoring NuGet package Selenium.Support.3.8.0.
Restoring NuGet package Selenium.WebDriver.3.8.0.
Restoring NuGet package Castle.Core.4.2.1.
Restoring NuGet package MSTest.TestFramework.1.2.0.
Restoring NuGet package Newtonsoft.Json.10.0.3.
Restoring NuGet package MSTest.TestAdapter.1.2.0.
Adding package 'MSTest.TestFramework.1.2.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Selenium.Support.3.8.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Castle.Core.4.2.1' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Selenium.WebDriver.3.8.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Newtonsoft.Json.10.0.3' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'MSTest.TestAdapter.1.2.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Selenium.Support.3.8.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Selenium.WebDriver.3.8.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Castle.Core.4.2.1' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Newtonsoft.Json.10.0.3' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'MSTest.TestAdapter.1.2.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'MSTest.TestFramework.1.2.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
NuGet Config files used:
C:\Users\StackOverflow\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.FallbackLocation.config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
Feeds used:
C:\Users\StackOverflow\.nuget\packages\
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
Installed:
7 package(s) to packages.config projects
Then run dotnet build.
It won't try to run dotnet restore as the packages have already been restored by NuGet already so you won't get any errors:
PS C:\Users\StackOverflow\NotepadAndCalculatorTest> dotnet build
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Nothing to do. None of the projects specified contain packages to restore.
NotepadCalculatorTest -> C:\Users\StackOverflow\NotepadAndCalculatorTest\bin\Debug\NotepadCalculatorTest.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.08
2. Port the project
The 2nd workaround is to create a new project using dotnet new & port the code over so that your .csproj file works with dotnet restore and subsequently, dotnet build.
I would recommend option 1 unless you don't want to restore via NuGet.

error CS0234: The type or namespace name 'OAuth' does not exist in the namespace 'Microsoft.Owin.Security' (are you missing an assembly reference?)

I am trying to build a project with cli:
msbuild.exe project.sln
I get errors of this type:
App_Start\NinjectConfig.cs(3,31): error CS0234: The type or namespace name 'OAuth' does not exist in the namespace 'Microsoft.Owin.Security' (are you missing an assembly reference?) [path_to_file\file.csproj]
I tried nuget restor
Also I have in root directory of my project folder for packges in which you have packages\Microsoft.Owin.Security.OAuth.3.0.1\lib\net45 with Microsoft.Owin.Security.OAuth.dll file.
In file.csproj I have a reference:
<Reference Include="Microsoft.Owin.Security.OAuth">
<HintPath>..\..\packages\Microsoft.Owin.Security.OAuth.2.1.0\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
I can see the differences in versions, but there are 2 questions:
1) why visual studio is building this with no errors? How come it works with vs but not with cli?
2) Why is nuget installing wrong version?
3) How can I export from vs a config for nuget to install all packages?
I am a newbie - so be gentle please.
1) why visual studio is building this with no errors? How come it works with vs but not with cli?
Since we do not have your project/solution, we could not figure out the reason why the Visual Studio is building with no error. But if you resolve your latter two problems, you will not be confused about this problem.
2) Why is nuget installing wrong version?
NuGet not install the project to the project file when you use the nuget restore command line. This command line just Downloads and installs any packages missing from the packages folder, So it not change the nuget package version in the file.csproj when you use that command line, it just download the package Microsoft.Owin.Security.OAuth.3.0.1 and set it to the \packages folder based on the nuget.config file, it will not check the HintPath in the project file. That is also the reason why you can see the nuget package in root directory of your project folder.
However, the path and version is not correct in the file.csproj(Could not know the reason, may be accidentally changed manually or for other reasons), it should be:
<HintPath>..\packages\Microsoft.Owin.Security.OAuth.3.0.1\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
Single ..\ and version is 3.0.1.
So, to resolve this issue, we should re-install the nuget package instead of restore it. You can uninstall it and reinstall that packages.
3) How can I export from vs a config for nuget to install all packages?
There is a packages.config file in your project, you can install the all the packages with Package Manager Console in Visual Studio, but you could not install all the packages with nuget CLI. Because package manager console is providing is access to visual studio objects.
Check another thread for some more details.
Hope this helps.

xamarin git pull nuget package error

I am new in Xamarin android development.
I take the code pull from git.
After that i opened my solution in visual studio.
I cleaned the solution - now it is fine.
then i trying to build the solution it is showing the error.
>Restoring NuGet packages...
To prevent NuGet from restoring packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck 'Allow NuGet to download missing packages during build.'
NuGet Package restore failed for project app: Unable to find version '2.0.0' of package 'FastAndroidCamera'.
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\: Package 'FastAndroidCamera.2.0.0' is not found on source 'C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\'.
https://api.nuget.org/v3/index.json: Unable to load the service index for source https://api.nuget.org/v3/index.json.
An error occurred while sending the request.
The remote name could not be resolved: 'api.nuget.org'
1>------ Rebuild All started: Project: app, Configuration: Debug Any CPU ------
1>D:\PRANAV\TOLL\GIT\MobileApp-12-06-2018\MobileApp\app\app.csproj(467,5): error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Xamarin.Build.Download.0.4.3\build\Xamarin.Build.Download.props.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========\
This is the error that i am getting . So guys can you figure where i am doing the mistakes ?
According to the error message,
To prevent NuGet from restoring packages during build, open the Visual
Studio Options dialog, click on the Package Manager node and uncheck
'Allow NuGet to download missing packages during build.'
It seems the project use the older now deprecated NuGet package restore that is MSBuild based and runs NuGet.exe on every build. These messages are from NuGet.exe.
Check the similar issue here.
To resolve this issue, you should make sure to upgrade to the latest version of NuGet which does package restore automatically instead of MSBuild based NuGet package restore.
You're going to want to delete the NuGet targets (delete the .nuget folder and then manually edit your .csproj files and remove the lines that import the NuGet.targets file). This is no longer needed. Using the new way to restore nuget package, the NuGet packages will be automatically restored by Visual Studio just before the build.
See this post by David Ebbo for more information: http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html and the blog how to switch from "Enable Package Restore" to "Automatic Package Restore"
Hope this helps.

Where to place NuGet

I have downloaded Google WEB API sample project. Solution explorer contains .nuget folder that is missing on my machine. NuGet itself is installed on my system. Currently build project rices error:
Error 1 This project references NuGet package(s) that are missing on
this computer. Enable NuGet Package Restore to download them. For
more information, see http://go.microsoft.com/fwlink/?LinkID=322105.
The missing file is
C:\pro\gplus-quickstart-csharp-master\.nuget\NuGet.targets. C:\pro\gplus-quickstart-csharp-master\gplus-quickstart-csharp\gplus-quickstart-csharp.csproj 196 5 gplus-quickstart-csharp
If I remove .nuget folder I have the same error.
How to configure NuGet in my system to make project build?
Have you tried Tools -> Options -> Nuget Package Manager and then selecting Allow Nuget to download missing packages?
Then rebuild your solution

Can't build solution because of missing NuGet references

Like title says, I can not build my solution(C#) as NuGet is spitting out this error
This project references NuGet package(s) that are missing on this
computer. Use NuGet Package Restore to download them. For more
information, see http://go.microsoft.com/fwlink/?LinkID=322105. The
missing file is ..\packages\Fody.1.26.1\build\Fody.targets.
When I run Get-Package, it says no packages are installed.
How do I get rid of this(I have no need for the package anymore).
Thanks
You don't want to use the project based nuget package restore!
Make sure you have the latest Nuget version (Tools -> Extensions and Updates)
When you go to build the project it should tell you it needs to download the nuget packages (or might just auto download them).
Edit not sure whats with the downvotes:
http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html
To find the menu item: "enable nuget package restore" right-click in the solution explorer on the solution - not on the project.
You get a message:
Do you want to configure this solution to download and
restore missing NuGet packages during build?
Press Ctrl+Q then type "Package Manager Console", This will bring up a console like interface.
Type in
Uninstall-Package Fody
and press enter will remove this package for you

Categories