DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Data
  4. NuGet, Cache, and Some More Problems

NuGet, Cache, and Some More Problems

We take a look at a few problems you might come across while using NuGet along with their fixes. Save some frustration and have a read!

Juergen Gutsch user avatar by
Juergen Gutsch
·
Nov. 28, 17 · Tutorial
Like (4)
Save
Tweet
Share
6.58K Views

Join the DZone community and get the full member experience.

Join For Free

recently i had some problems using nuget, two of them were huge, which took me a while to solve them. but all of them are easy to fix, if you know how to do it.

nuget cache

the first and most critical problem was related to the nuget cache in .net core projects. it seems the underlying problem was a broken package in the cache. i didn't find out the real reason. anyway, every time i tried to restore or add packages, i got an error message, that told me about an error at the first character in the project.assets.json. yes, there is still a kind of a project.json even in .net core 2.0 projects. this file is in the "obj" folder of a .net core project and stores all information about the nuget packages.

this error looked like a typical encoding error. this happens often if you try to read an ansi encoded file, from a utf-8 encoded file, or vice versa. but the project.assets.json was absolutely fine. it seemed to be a problem with one of the packages. it worked with the predefined .net core or asp.net core packages, but it doesn't with any other. i wasn't able anymore to work on any .net core projects that target .net core, but it worked with projects that are targeting the full .net framework.

i couldn't solve the real problem and i didn't really want to go through all of the packages to find the broken one. the .net cli provides a nice tool to manage the nuget cache. it provides a more detailed cli to nuget.

dotnet nuget --help

this shows you tree different commands to work with nuget. delete and push are working on the remote server to delete a package from a server or to push a new package to the server using the nuget api. the third one is a command to work with local resources:

dotnet nuget locals --help

this command shows you the help about the locals command. try the next one to get a list of local nuget resources:

dotnet nuget locals all --list

you can now use the clear option to clear all caches:

dotnet nuget locals all --clear

or a specific one by naming it:

dotnet nuget locals http-cache --clear

this is much easier than searching for all the different cache locations and to delete them manually.

this solved my problem. the broken package was gone from all the caches and i was able to load the new, clean and healthy ones from nuget.

versions numbers in packages folders

the second huge problem is not related to .net core, but to classic .net framework projects using nuget. if you also use git-flow to manage your source code, you'll have at least to different main branches: master and develop . both branches contain different versions. master contains the current version code and develop contains the next version code. it is also possible that both versions use different versions of dependent nuget packages. and here is the problem:

master used awesomepackage 1.2.0 and develop uses awesomepackage 1.3.0-beta-build54321.

both versions of the code are referencing to the awesomelib.dll but in different locations:

  • master: /packages/awesomepackage 1.2.0/lib/net4.6/awesomelib.dll
  • develop: /packages/awesomepackage 1.3.0-beta-build54321/lib/net4.6/awesomelib.dll

if you now release the develop to master , you'll definitely forget to go to all the projects to change the reference paths, don't you? the build of the master will fail, because this specific beta folder won't exist on the server, or even worse: the build will not fail because the folder of the old package still exists on the build server because you didn't clear the build workspace. this will result in runtime errors. this problem will probably happen more likely, if you provide your own packages using your own nuget server.

i solved this by using a different nuget client than nuget. i use paket because it doesn't store the binaries in version specific folder and the reference path will be the same as long as the package name doesn't change. using paket i don't need to take care of reference paths and every branch loads the dependencies from the same location.

paket officially supports the nuget apis and is mentioned on nuget org, in the package details.

to learn more about paket visit the official documentation: https://fsprojects.github.io/paket/

conclusion

being an agile developer doesn't only mean to follow an iterative process. it also means to use the best tools you can buy. but you don't always need to buy the best tools. many of them are open source and free to use. just help them by donating some bugs, spread the word, file some issues or contribute in a way to improve the tool. paket is one of such tools, lightweight, fast, easy to use and it solves many problems. it is also well supported in cake , which is the build dsl i use to build, test and deploy applications.

NuGet Cache (computing) .NET

Published at DZone with permission of Juergen Gutsch, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • The 31 Flavors of Data Lineage and Why Vanilla Doesn’t Cut It
  • Best Practices for Writing Clean and Maintainable Code
  • How To Validate Three Common Document Types in Python
  • Distributed Stateful Edge Platforms

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: