Reputation: 6187
I'm trying to use nopCommerce(Which is written in .NET Core) but when I want to run the project I face 52 Errors telling me Run a nuget package restore
Assets file ~\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. Nop.Web.MVC.Testsote
when I use the right click on the solution and selecting Restore Nuget Packages I get this message:
All packages are already installed and there is nothing to restore.
but those 52 Errors are still there and in Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution there is nothing installed on the solution,also I Recently updated my VS2017 to 15.5.4
Upvotes: 592
Views: 472797
Reputation: 1421
In case when dotnet restore
doesn't work, following steps may help:
Upvotes: 96
Reputation: 2603
Not yet mentioned is the possibility that Windows has not been opted in to support long file paths.
Update the build machine's registry so the LongPathsEnabled
value is set to 1
. Other tools involved in the NuGet restore and build may require their own configuration to support Windows long file paths (for instance, Git).
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001
Upvotes: -1
Reputation: 146
This may be obvious or an edge case but check your path as well.
When I cloned the repo I got this path:
repos\MyRepo\Field%20Service%20Project\Azure Functions\func-dev-sat-eus-01\obj\project.assets.json
The escaped characters confused the build command so that it could not reach the file because it could not find that folder.
In my case, I just replaced the '%20' with an actual space in the directory name.
Upvotes: 2
Reputation: 1592
Alright I might have two causes to your problem, it's the exact the same error and related to NuGet (restoring), so many users might face the same issue and end up here. So three options:
Upvotes: 1
Reputation: 1554
I had this issue on a Teamcity build. I had a build step
of type nuget installer
. Inside it there's a setting named Restore mode
. The fix for me was to set its value to Restore
(it was set to install
)
Upvotes: 0
Reputation: 81
I got this error and missed the error above it saying missing workload. Fixed by running:
dotnet workload install <workloadname>
In my case
dotnet workload install wasm-tools-net7
Upvotes: 0
Reputation: 642
Wow. This one has clearly been giving people trouble (including myself). As others have noted, it seems that a large number of failure cases may lead to a similar set of evidence.
Anyway, for me I was getting this "project.assets.json not found" error when trying to publish. After trying many of the suggestions found here, and elsewhere, and losing a half-day, I found something that got me unstuck and I thought I'd add my solution in case it helps anyone.
Ensure that the directory "{PROJECT-ROOT}\obj\publish\browser-wasm" exists, creating it if needed.
Find these 5 files in your "{PROJECT-ROOT}\obj" directory:
project.assets.json
project.nuget.cache
{PROJECT-NAME}.csproj.nuget.dgspec.json
{PROJECT-NAME}.csproj.nuget.g.props
{PROJECT-NAME}.csproj.nuget.g.targets
Copy those 5 files into "{PROJECT-ROOT}\obj\publish\browser-wasm", overwriting them if needed.
If the dependencies for any projects that are dependencies of your project have changed then you should do steps 1, 2, and 3 for each of those projects as well.
Restart Visual Studio.
This got me unstuck and I am now able to publish. However, I do need to re-do this each time I add new Dependencies to my project.
Upvotes: 1
Reputation: 129
To fixed this issue. First you have to close the Visual Studio, then restart again in administrative mode.
Create an new project or run your older project. Then Go
Tools > NuGetPackage Package Manager > Package Manager Console
An console will be open in below
Then put a command
dotnet restore
It will fixed all your problem.
Upvotes: 10
Reputation: 1517
To those with the same issue as me in Azure DevOps / VSTS environment encountering a similar message:
C:\Program Files\dotnet\sdk\2.2.104\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(208,5): Error NETSDK1004: Assets file '...\obj\project.assets.json' not found. Run a NuGet package restore to generate this file
Add /t:Restore
to your MSBuild Arguments in Build Solution.
In Azure DevOps build pipeline, add /t:Restore
here:
Upvotes: 86
Reputation: 359
I did not have any NuGet in my CLI/C++. VS2022 built fine. However, MSBuild did not work giving me error NETSDK1004: Assets file ... obj\project.assets.json' not found. Run a NuGet package restore to generate this file.
The solution to my issue was removing the following from the vcxproj file.
<EnableManagedPackageReferenceSupport>true</EnableManagedPackageReferenceSupport>
I suppose changing true to false might work. I removed the line and MSBuild now works.
Upvotes: 3
Reputation: 365
I haven't found anywhere the method suggested by Microsoft which is to delete the "packages
" folder.
Source: Troubleshooting package restore errors
You may encounter build errors due to missing files, with a message saying to use NuGet restore to download them. However, running a restore might say, "All packages are already installed and there is nothing to restore." In this case, delete the
packages
folder (when usingpackages.config
) or theobj/project.assets.json
file (when using PackageReference) and run restore again. If the error still persists, usenuget locals all -clear
ordotnet nuget locals all --clear
from the command line to clear the global-packages and cache folders as described on Managing the global packages and cache folders.
Upvotes: 0
Reputation: 417
For me when i did - dotnet restore still error was occurring.
I went to
1 Tool -> NuGet Package Maneger -> Package Manager settings -> click on "Clear all NuGet Cache(s)"
2 dotnet restore
resolved issues.
Upvotes: 27
Reputation: 35115
In my case it was .net6 project and the build happening on DevOps windows-2019 agent.
Solution: windows-2022 can build .net6.
Upvotes: 1
Reputation: 240
Had a similar issue. Turned out that I did not have access to %APPDATA%\Local\Temp\NuGetScratch\lock
Once I had access I could run nuget restore, but everything did start working.
Upvotes: 0
Reputation: 13479
I have same problem and dotnet resotre
not work for me. I Install this component:
and the run dotnet resotre
and the problem has solved.
Upvotes: 4
Reputation: 157
What worked for me when I got this error was adding a global.json file but that may be related to using Paket instead of Nuget.
Upvotes: 0
Reputation: 3625
My issue was the build configuration platform was mismatched. Once, I changed "Any CPU" to "x64", I was able to publish.
Upvotes: 3
Reputation: 12371
In my case, I had the following added to my *.csproj files to fully remove obj and bin folders on 'Clean'. Apparently, it was the culprit. Got rid of that and viola, all started to work again. Now I'm using the "Clean Bin" extension instead. Hope this might help anyone who is running into this issue, and none of the mentioned fixes works.
<Target Name="SuperClean" AfterTargets="Clean">
<!-- Remove obj folder -->
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
<!-- Remove bin folder -->
<RemoveDir Directories="$(BaseOutputPath)" />
</Target>
Upvotes: 1
Reputation: 1563
I received one message on Azure DevOps about don't find file
i need to create this on my YAML deployment file, AFTER BUILD TASK
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '**\*.sln'
feedsToUse: 'config'
noCache: false
Upvotes: 0
Reputation: 306
You will get required packages from "https://api.nuget.org/v3/index.json". Add this in Package Resources. Also make sure other packages are unchecked for time being. And Click Restore Nuget Package on Solution Explorer
Upvotes: 9
Reputation: 479
It was mentioned earlier but I just wanted to re-emphasize the importance of not have space anywhere in your pathing! This is what was getting me. You've been warned.
Upvotes: 10
Reputation: 2882
Closing and re-opening Visual Studio solved this issue for me, once I had made sure the NuGet packages had been restored as per other answers posted here.
Edit: Sometimes just trying to build again fixes the problem.
Upvotes: 53
Reputation: 107
You can go for : Tools > NuGet Package Manager > Package Manager Console
And then Run:
dotnet restore
Upvotes: 6
Reputation: 501
If this error occurs as part of a build in Azure DevOps (TFS) and your build already has a NuGet restore task, this error may indicate the NuGet restore task was not able to restore all packages, especially if you use a custom package source (such as an internal NuGet server). Adding /t:Restore;Build
to the MSBuild Arguments seems to be one way to resolve the error, but this asks MSBuild to perform an additional NuGet restore operation. I believe this succeeds because MSBuild uses the custom package source configured in Visual Studio. A preferable solution is to fix the NuGet restore task.
To configure a custom package source for the NuGet restore task:
NuGet.config
file that lists all of the package sources (Microsoft Visual Studio Offline Packages, nuget.org, and your custom package source) and add it to source control.NuGet.config
./t:Restore;Build
option from the MSBuild task.Additional information is available here.
Upvotes: 12
Reputation: 1
Try this (It worked for me):
Upvotes: -1
Reputation: 1000
For me it turned out to be a nuget source credentials problem. I had recently changed my password for accessing a nexus server and visual studio was still using the old password when trying to access a nuget on that server through the windows credential manager. To fix it, I had to delete the entry for those outdated credentials in the credential manager and after, when I did a nuget restore, it prompted me for a password letting me enter the new password, which got saved in the credential manager again. You can access the credential manager from the cmd line using CmdKey.exe.
Upvotes: 0
Reputation: 2069
Seen this after adding a WinForms Core 3.1 project (from project templates) on VS-2019 vs 16.4.0 and trying to run it out of the box. Clean or Rebuild the entire solution did not work.
I just reloaded my solution.. that is File/Close Solution and then reopening it and rebuilding it solved the problem.
Upvotes: 0
Reputation: 523
Very weird experience I have encountered!
I had cloned with GIT bash and GIT cmd-Line earlier, I encountered the above issues.
Later, I cloned with Tortoise-GIT and everything worked as expected.
May be this is a crazy answer, but trying with this once may save your time!
Upvotes: 0
Reputation: 19384
This problem happening when your build tool is not set to do restore
on projects set to use PackageReference
vs packages.config
and mostly affect Net Core and Netstandard new style projects.
When you open Visual Studio and build, it resolves this for you. But if you use automation, CLI tools, you see this issue.
Many solutions are offered here. But all you need to remember, you need to force restore
. In some instances you use dotnet restore
before build. If you build using MsBuild just add /t:Restore
switch to your command.
Bottom line, you need to see why restoring can't be activated. Either bad nuget source or missing restore action, or outdated nuget.exe, or all of the above.
Upvotes: 5