Nuget Packages show Yellow Triangle When Reinstalling or Installing New - visual-studio-2019

I am experiencing an issue that I have never seen before. I opened an old application (I believe it was created with VS 2015) in Visual Studio 2019, and all Nuget packages show yellow triangles. I tried Update-Package -reinstall, I watch each package get reinstalled, and they still show yellow triangles. I tried uninstalling and reinstalling using Nuget Package Manager and as soon as the package is installed it shows the yellow triangle. I tried deleting the reference and manually adding the dll from packages folder in the solution, and I get the same thing.
I saw a post where someone suggested removing the following from the project file:
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
Which also didn't work. I also tried adding packages that didn't already exist in the app, and after installing they too show with a yellow triangle. Also, all packages show Copy Local = False.
Any suggestions are greatly appreciated.

Related

Cannot find compilation library location for package when Publishing - .Net Core 2.0 - Visual Studio 2017 15.8.5

I have a .Net Core 2.0 project, which references a project that in turn has an assembly reference. All was working fine until I upgraded Visual Studio 2017 to version 15.8.5.
After the upgrade, when I tried to run the project in VS, I got the error "Cannot find compilation library location for package". This was surprising, since I was not getting it previously, but I had seen this issue before, and had resolved it by a hack needed for assembly references with .Net Core 2.0, specifically, replacing the default MetadataReferenceFeatureProvider (for details, see https://github.com/dotnet/core-setup/issues/2981). Once I did this, the project built and ran fine in Visual Studio.
However, when I tried to Publish the project, I got the same error again. Currently, I am unable to publish.
Does anybody know what I can do about this? (The project needs a compiled MVC view, so I can't disable the compilation using false.)
I am getting desperate, and am considering rolling back to a prior version of Visual Studio (if that is even possible!). It is so frustrating that Microsoft urges you to update VS, then the update breaks what used to work!
Here is the stacktrace:
Cannot find compilation library location for package 'ShiftSchedulerSPA.Reference'
at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List1 assemblies)
at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
at Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPart.<>c.<GetReferencePaths>b__8_0(CompilationLibrary library)
at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext()
at Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvider.PopulateFeature(IEnumerable1 parts, MetadataReferenceFeature feature)
at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature[TFeature](TFeature feature)
at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorReferenceManager.GetCompilationReferences()
at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func1 valueFactory)
at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorReferenceManager.get_CompilationReferences()
at Microsoft.AspNetCore.Mvc.Razor.Internal.LazyMetadataReferenceFeature.get_References()
at Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature.GetDescriptors()
at Microsoft.AspNetCore.Razor.Language.DefaultRazorTagHelperBinderPhase.ExecuteCore(RazorCodeDocument codeDocument)
at Microsoft.AspNetCore.Razor.Language.RazorEnginePhaseBase.Execute(RazorCodeDocument codeDocument)
at Microsoft.AspNetCore.Razor.Language.DefaultRazorEngine.Process(RazorCodeDocument document)
at Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine.GenerateCode(RazorCodeDocument codeDocument)
at Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine.GenerateCode(RazorProjectItem projectItem)
at Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine.GenerateCode(String path)
at Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal.PrecompileRunCommand.<>c__DisplayClass23_0.b__0(Int32 i)
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
The solution was actually found in the referenced github article above. I don't know why it broke after the VS 2017 upgrade, but the fix for the publish problem was to edit the .csproj file to change the Microsoft.AspNetCore.All from version 2.0.0 to 2.0.3:
<ItemGroup>
<PackageReference Include="IdentityModel" Version="2.16.1" />
<PackageReference Include="IdentityServer4" Version="2.0.6" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="1.1.0" />
</ItemGroup>

TFS not building after download

I just downloaded the current revision from TFS. However even after restoring the nuget packages it isn't building. Something about missing Nugets.
Any assistance would be appreciated. Is this because we are using different Visual studio versions?
I'm opening the csproj file to build my sln file.
Try following below steps to fix that:
Close Visual Studio
Manually delete the local “packages” folder
Reopen the solution, and rebuild. (Nuget should restore the
packages)
Source Link: Missing Nuget Packages on TFS Build Server
Or run the update-package -reinstall command in NuGet Package Management Console to reinstall all referenced packages.
If that still not work, just try this:
Right click on .csproj and open it in notepad or any editor and delete the following
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
Then build your solution and it should work.
And this thread for your reference: NuGet not restoring packages on build

NuGet Package restore failed for project PROJECT: Unable to find version 2.0.0 of package 'Microsoft.Net.Compilers'

I used the GitHub extension of Visual Studio 2015 to clone my project onto a new computer. I try to restore packages and I get an error that says:
NuGet Package restore failed for project PROJECT: Unable to find version 2.0.0 of package 'Microsoft.Net.Compilers'
I've looked into some other questions about similar issues, but none of those solutions have worked for me yet.
I tried deleting the packages folder, opening up up Visual Studios again and then rebuilding. That didn't resolve it.
I tried manually installing Microsoft.Net.Compilers in Package Manager Console.
PM> Install-Package Microsoft.Net.Compilers
I tried removing this bit of code from the csproj file (this seemed to work for some):
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
I tried reinstalling all packages with
Update-Package –reinstall
So far I haven't had any luck resolving the issue. Any help is appreciated.
EDIT:
I tried the response below and received this error:
Install-Package : Some NuGet packages are missing from the solution. The packages need to be restored in order to build the dependency graph. Restore the packages before performing any operations.
At line:1 char:16
+ Install-Package <<<< -Id Microsoft.Net.Compilers -Version 1.3.2 -Source nuget.org
+ CategoryInfo : InvalidOperation: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetMissingPackages,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
It also prompted me to restore packages. When I hit restore, I got the same error as usual.
Based on your error message looks like you are looking for a version that no longer exists and cannot tell which Package source you have selected. I feel like you are looking for version 2.0.0 which is not available in nuget.org repository. The latest one is 2.0.0-rc and it is pre release candidate.
Please try this command if you want to get the latest version
Install-Package -Id Microsoft.Net.Compilers -Version 2.0.0-rc -Source nuget.org
If you want the latest stable version (1.3.2), try this command
Install-Package -Id Microsoft.Net.Compilers -Version 1.3.2 -Source nuget.org
UPDATE
If the package still cannot be installed, then that package may be out of sync between packages.config, packages/ folder and .csproj file
Please follow these steps to perform manual cleanup
Close visual studio.
Open .csproj in a notepad or some text editor and manually remove all entries related to Microsoft.Net.Compilers
Open packages.config in a notepad or some text editor and and remove entry for the Microsoft.Net.Compilers package
Go to packages/ folder in windows explorer and delete the Microsoft.Net.Compilers folder
Now start the visual studio and open the solution.
Now try to install the package again.
Some of the entries that you may have to remove from .csproj as part of step 2 are these
<Import Project="..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" />
<NuGetPackageImportStamp></NuGetPackageImportStamp>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props'))" />
</Target>
I had a similar error after a clean install of Visual Studio 2017 and had to do the following to get it to automatically restore missing NuGet packages successfully. In VS, go to "Tools > Options > NuGet Package Manager > Package Sources", and ensure the appropriate package sources show and are checked.
See below. The addition of the nuget.org package source at the top tells VS to go online to download the packages from NuGet if it can’t find the appropriate versions on the local machine.
I also had similar problem on VS 2019, this one worked for me, just go to Tools > Options > NuGet Package Manager > General and Clear all NuGet Cache.
See the image below
This might be a bit late but it will still help somebody. When you try to check in your code and you get this kind of an error, it means that you had the package installed and uninstalled it again, so you just need to locate the package under included changes, in my example i an using TFS, and exclude or undo. this will solve the issue.
I moved my project in relation to where the NuGet packages had originally been stored in my project, and I eventually discovered that this causes a problem with that .csproj file that might not be immediately obvious.
Following the move and after doing a NuGet Package Restore, a second entry had been added to the EnsureNuGetPackageBuildImports target of my .csproj file reflecting the relative path of the new location.
The target now looked like the following:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props'))" />
</Target>
Notice the two entries, with different paths to where the packages were located. This meant one of them (the first one, which was from before I moved the project) would always fail.
The fix was simple enough. I just removed the first Error node from the Target.
I also found that there was a similar problem in the initial Import nodes of the root Project node.
I had the following:
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.2.10.0\build\Microsoft.Net.Compilers.props')" />
Again, the fix was just to remove the erroneous Import node.
This kind of error can happen also using an old version of nuget.exe. For example, if you download the agent.zip of TFS 2015, inside it has version 3.2.1:
\Agent\Worker\Tools\nuget.exe
That version can give the error "Unable to find version '3.7.1' of package 'NUnit'." with a solution created with VS 2015. (NUnit3TestAdapter.3.9.0 doesn't give error, though)
Updating nuget.exe to 5.2 solves the problem.
I know why, it's in the C: \ Program Files (x86) \ Microsoft SDKs \ NuGetPackages folder. There are packages that you have installed before.
This was my error: "The project references NuGet packages that are missing on this computer. Use NuGet Package Restore to download them."
And this was my solution: I had to make sure that my Package Sources were checked in the Manage Nuget Packages window.
go to tools in navbar and tools and features and chek your freamworks are downloaded or not
enter image description here

Assemblies not being copied across from a Nuget Package

We have a WCF webservice that is targetting .NET framework 4.0. This WCF, uses a assembly from the same Visual Studio project that in turn uses a couple of Nuget Packages like so below:
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.30506.0" targetFramework="net40" />
This Nuget package is adding two assemblies to the "System.Net.Http" and "System.Net.Http.Formatting" to the project. When this application is getting deployed using TFS Build, for some reason these two assemblies are not getting copied to the bin folder on the server. When I check the "Copy Local" flag for these two assemblies, I see that they are set to TRUE.
I have uninstalled the Nuget packages and installed it again, but doesn't seem to work.
Any suggestions as to what could be wrong?

No update version shown up for nuget even while two assemblies have different versions

I am new to nuget and but realized that my recent ASP.net MVC4 project already included it so I also added packages to other projects of that solution. But that was curious; now I had two versions of Json.Net
v. 4.5.6 within the ASP.net MVC project
v. 5.0.6 within any other project
So what says the nuget docs... OK then, lets update. I opened the Package Manager Console, chooses the ASP.net MVC project and typed Get-Package -updates with the result
No package updates are available from the current package source.
Which is the NuGet official package source
A look at the different packages.config showed me:
ASP.net MVC project
<package id="Newtonsoft.Json" version="4.5.6" targetFramework="net45" />
other project
<package id="Newtonsoft.Json" version="5.0.6" targetFramework="net45" />
So where am I wrong. Why didn't I see any updates available for the ASP.net MVC project
(please note that the Newtonsoft.Json package is just a example, I got the same thing for the Microsoft.AspNet.Mvc where it is not the major version that differs)
Any help appreciated.
I figured out how to get it updated. I opened the Solution Package Manager (Tools > Library Package Manager > Manage NuGet Packages for Solution)
Now I saw many duplicated entries from which I always choose the latest version, hit the manage button and added the solution that by now used the older version. NuGet now removed the the other entries and added the new one. It seems the Get-Package -updates always refer to the whole the solution (try Get-Package it will show the packages solution wide) and there I had the latest one listed.

Resources