Missing Packages After Cloning

Just a quick post!

Ever clone your .NET solution to a new computer and find that all of your nuget packages are missing?

Right-clicking on your solution and selecting "Restore Nuget Packages" doesn’t seem to do anything? This happens to me and then I never remember the command and have to google it. This time, I am going to write it down!

How To Do It

Open up your Package Manager Console window. It should be on the bottom, but if it isn’t, in your pull down menus, goto Tools | Nuget Package Manager | Package Manager Console. This was for Visual Studio 2019, but probably the same for 2017.

At the command prompt type:

update-package -reinstall

And that’s it! You should find all your annoying yellow warning triangles gone.

Nuget Versioning In Your Library

I was building up a library this morning, and I wanted to use Json.NET with it for deserializing. I was planning on using this library for a number of different apps, and it made me wonder, if I add a dependency such as Json.NET, will it cause problems if I am already consuming it in my app?

Nuget Versioning

For my library, version 10 or higher should be sufficient. I dug into the nuget docs and found a bunch of handy examples.

I installed 10.0.3 into my library project. In the project file itself, I changed the reference version from 10.0.3 to be just 10.0. According to the nuget docs, this will enable 10.0 to be the minimum version, and if there are higher versions, they will be accepted.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="a_class_file.cs" Link="a_class_file.cs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="10.0" />
  </ItemGroup>
</Project>

Other Versioning

Some other helpful items:

Notation Description
Version="[10.0,11.0]" includes anything from 10.0 to 11.0 including 10.0 and 11.0
Version="(,11.0]" Includes anything up to and including 11.0
Version="[11.0]" Only accept version 11.0

There are lots of other helpful examples in the documentation.