NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe): VS UI
VS version (if appropriate): 15.7.1
My repro used the full .NET framework, but I'm not sure if it affects solely .NET framework
Sample project contains steps up to and including step 4
NuGetStaleCache.zip
is the option to allow nuget to download missing packages and automatically check for missing packages during build in visual studio enabled?

Yes

I've been experiencing the same kind of issues.
In VS (testing with 15.8) the behavior is correct if you remove the package reference through UI, it will generate an empty project.assets.json and it will break the build as expected.
But as described in this issue if you remove the reference and build using msbuild.exe /restore it will still compile as project.assets.json is not being modified. The log says there's nothing to restore.
IMO NuGet packages should always be restored as it leads to weird build issues.
It's also visible (and more problematic) when you reference a project that itself references NuGet packages. You'll get acess to its references only when yourself has at least one package reference. (I'll attach a sample project in another comment)
There are two projects in this solution with that structure:
NoPackageReferences.csproj => LibWithPackageReference.csproj => Newtonsoft.json
In NoPackageReferences we try to access Newtonsoft.json but we end up with:
error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
If you add a package reference to another package in NoPackageReferences, let's say NUnit it will compile fine. A project.assets.json file will be generated containing the project reference:
"LibWithPackageReference/1.0.0": {
"type": "project",
"framework": ".NETFramework,Version=v4.6.1",
"dependencies": {
"Newtonsoft.Json": "11.0.2"
},
"compile": {
"bin/placeholder/LibWithPackageReference.dll": {}
},
"runtime": {
"bin/placeholder/LibWithPackageReference.dll": {}
}
Please note that adding those lines to NoPackageReferences.csproj will fix the issue:
<ResolveNuGetPackages>true</ResolveNuGetPackages>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Sample project 2
There are two projects in this solution with that structure:
NoPackageReferences.csproj=>LibWithPackageReference.csproj=>Newtonsoft.json
I have this situation all the time in my build configuration. I have to work around it by adding a dummy reference to some random small NuGet package in my executable project so that it is capable of consuming transitive dependencies from the projects it <ProjectReference/>s.
Please note that adding those lines to
NoPackageReferences.csprojwill fix the issue:<ResolveNuGetPackages>true</ResolveNuGetPackages> <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Oh, cool, missed this earlier! I had only added <RestoreProjectStyle>PackageReference</RestoreProjectStyle> to my Directory.Build.props file. Adding the other line fixes everything!