git clone http://Your%20Project%20With%20Spaces newprojectname
–
–
–
Visual Studio >> Tools >> Options >> Nuget Manager >> Package Sources
Unchecked any third party package sources.
Rebuild solution.
–
–
–
–
–
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:
–
–
–
–
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.
–
–
–
–
I went to
1 Tool -> NuGet Package Maneger -> Package Manager settings -> click on "Clear all NuGet Cache(s)"
2 dotnet restore
resolved issues.
–
In visual studio 2017 please do following steps:
1) select Tool=>Options=>NuGet Package Manager=> Package Sources then uncheck Microsoft Visual Studio Offline Packages Option.
2) now open Tool=>NuGet Package Maneger=>Package Manager Console.
3) execute command in PM>dotnet restore.
Hope its working...
–
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:
Create a 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.
In the Nuget restore task under Feeds to use: select the option Feeds in my NuGet.config.
Provide the path to NuGet.config
.
Remove the /t:Restore;Build
option from the MSBuild task.
Additional information is available here.
For me I upgraded NuGet.exe from 3.4 to 4.9 because 3.4 doesn't understand how to restore packages for .NET Core.
For details please see dotnet restore vs. nuget restore with teamcity
–
–
–
–
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.
–
little late to the answer but seems this will add value. Looking at the error - it seems to occur in CI/CD pipeline.
Just running "dotnet build" will be sufficient enough.
dotnet build
dotnet build runs the "restore" by default.
–
I lost several hours on this error in Azure DevOps when I set the 'Visual Studio Build' task in a build pipeline to build an individual project in my solution, rather than the whole solution.
Doing that means that DevOps either doesn't build any (or possibly some, I'm not sure which) of the projects referenced by the project you've targeted for the build, and therefore those projects won't have their project.json.asset files generated, which then causes this issue.
The solution for me was to swap from using the VS Build task to the MSBuild task. Using the MSBuild task for an individual project correctly builds any projects referenced by the project you're building and eliminates this error.
If simply restoring NuGet packages does not work make sure in Tools -> Options -> NuGet Package Manager -> General under Package Restore that the "Allow NuGet to download missing packages" is checked.
Then Restore NuGet Packages again OR just REBUILD after deleting obj and bin folders.
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.
–
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>
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.
–
Another one, if by any chance you're using Dropbox, check for Conflicted
in file names, do a search in your repo and delete all those conflicted files.
This may have happened if you have moved the files around.
Cause of this defect: you have to remove the injected Nuget in file explorer.
Solution: Once you remove that Nuget in your system, then remove from following location.
select Tool=>Options=>NuGet Package Manager=> Package Sources then uncheck Microsoft Visual Studio Offline Packages Option
added this package source:
Microsoft and .net
https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/
then run "dotnet restore" in the console
In my case I had a problem with the Available Package Sources. I had move the local nuget repository folder to a new path but I did not update it in the Nuget Available Package Sources. When I've correct the path issue, update it in the Available Package Sources and after that everything (nuget restor, etc) was working fine.
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!