I have a couple of projects where under Dependencies there are one or two branches of code analyzers like this:
I tried the right mouse click on every branch as explaind here but there is no option to configure them and I also searched for *.ruleset files insinde the solution, I also check the packages as shown in the docs but there is nothing like that anywhere.
There is also nothing suspicious in the .csproj files, just some nuget packages that I've installed but nothing analyzer related.
How do I get rid of them? They give me warnings when I reference such projects in other solutions and nuget restore doesn't fix it either:
I have no idea where they come from. Some projects have them and others don't. However, they seem to somehow be related to ASP.NET Core or MVC packages that are installed in those projects.
There is a bug in Visual Studio and it is supposed to be fixed soon.
When Visual Studio loads all projects for the solution and tries to resolve all dependencies to display in Solution Explorer, some dependencies may fail and display as warnings with the path of the likely file for the dependency.
Workaround:
Right click the project with the warnings, and select Unload Project on the menu. Then right click it again and select Reload Project. Because Visual Studio is less busy with background processes than it was when it was loading everything for the entire solution, it is likely to resolve the dependency. It seems to always work for me.
I've fixed the warnings by deleting the microsoft.codeanalysis.analyzers folder and executing nuget restore. They are still under Dependencies but at least the exclamation marks are gone.
I've also managed to remove the analyzers by adding the <ExcludeAssets>analyzers</ExcludeAssets> directive to each AspNetCore package:
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3">
<ExcludeAssets>analyzers</ExcludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.1" >
<ExcludeAssets>analyzers</ExcludeAssets>
</PackageReference>
Now they're finally gone.
Search Gcop in nuget package manager removes the installed packages
prefixed with GCop. this will remove the code analyzer references from
your project
Related
Is there a way to disable updates of specific nuget packages installed in a project?
I have made some local modifications to a couple of javascript library packages and do not want to run the risk of someone updating over the top of my changes in the future.
I've never created my own nuget package, I'm guessing one option might be to fork the existing packages?
You could try constraining the package so it your project will only allow a particular version to be used. Then all updates to any newer version will be prevented.
You can do this by editing your project's package.config file. For example, the line below should only allow version 2.1.0 to be used.
<package id="SomePackage" version="2.1.0" allowedVersions="[2.1.0]" />
I don't have a package.config. (VS 2019, .NET Core 3.1) What I did instead was changing the .csproj of the project which had the package which I needed to stop showing up for updates.
In my case it was EPPlus, and I wrapped the version number within square brackets.
<ItemGroup>
<PackageReference Include="EPPlus" Version="[4.5.3.3]" />
</ItemGroup>
After that, it stopped showing up on the Updates tab in Nuget Package Manager.
And it doesn't give any option to update from anywhere else too. (Installed tab, Nuget for the solution, etc)
You'll need to restart VS to get rid of the yellow triangles next to the packages.
EDIT:
WARNING: Please note that this work only for "Manage nuget packages for [project]" (which is rarelly used), not "Manage nuget packages for Solution" (which is the one you use every other day). See comments.
So this is no solution at all. I will keep it here for some random googlers who will try this, but it is almost useless.
For PackageReference you can block update on single version like this:
<PackageReference Include="IdentityServer4.AspNetIdentity">`
<Version>[3.1.1]</Version>
</PackageReference>
For some reason it have to be in own element and not in attribute, so you are stuck with editing your .csproj by hand.
VS2019 will look funny (some yellow triangles) but just restart it and it will take effect.
It is not the same as allowedVersions= becouse AFAIK you can lock to exactly one version only (for example, [3.1.0, 3.1.1] or (3.0.0, 3.1.1] or whatever else does NOT work!)
(i know i am necromanting this question - accepted answer is about older <Package />, my answer is about newer <PackageReference />)
My csproj has the following lines:
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<Deterministic>False</Deterministic>
<ItemGroup>
<ProjectReference Include="..\blah.Common\blah.Common.csproj" />
<ProjectReference Include="..\blah.Model\blah.Model.csproj" />
</ItemGroup>
The referenced projects build fine. However in the VS tree these two projects randomly disappear from the Dependencies tree and VS reports the references as missing and the build passes.
Reloading/rebuilding/cleaning/restarting/removing then adding the projects again in no particular order usually fixes it. Problem comes back after a legitimate build error crops up in another project.
I am using Resharper and VS2017
I have tried dotnet restore with no luck. Any ideas why this one particular project is constantly losing its references?
Edit: I just realised I incorrectly mentioned the build as FAILING. It does not fail and builds successfully, however my project is litered with red errors and warnings saying references are missing. After a successful build the red warnings/errors disappear then randomly come back again.
Sometimes the projects are literally missing from the references tree, other times they are visible. When right clicking "add reference" the project is already ticked however. Unloading the project and reloading or doing a full rebuild fixes the "Error" only for it to come back at some point.
Even though the "Error List" is filled with missing reference errors, a clean and full build produces no errors and creates a successful build.
Did you check the .NET framework version that these 3 projects are targeting?
Incompatibility between framework versions allows the reference to get added but results in missing references during build/run time. To validate if this is indeed the problem, you can check the warnings that Visual Studio produces while building the solution. An alternative way of finding the root cause of the problem, would be to add one of the projects as a DLL reference while keeping the other as a project reference. If the DLL reference doesn't work, it means there is some configuration mismatch between the source and target projects (e.g. .NET framework version). If the DLL version works, then it means Project References are broken, in which case you can check if path provided is correct.
Due to some git project changes, when I try to build, I get an error:
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 ..\packages\MSTest.TestAdapter.1.1.11\build\net45\MSTest.TestAdapter.props.
The references to the project contain four missing references, two of which Microsoft.VisualStudio.TestPlatform.TestFramework, and Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions which seem to be related.
The other two, in case it proves to be relevant are System, and System.Core, but they aren't causing any problems... which is weird, cause I'm definately using them.
That missing file, the one from the error message, is absolutely there.
I've tried to uninstall and reinstall both packages, but nothing seems to help.
Open the projects .csproj file with your favourite text editor and delete any references to
MSTest.TestAdapter.props.
Edit: This is safe to do so, all that happened is that you have removed the DLL but for one reason or another your project file still references it as a dependency.
I would modify #JoshuaDuxbury's answer to say: you need to clean out obsolete references to MSTest.TestAdapter.props.
In my case, I had just updated the MSTest.TestAdapter NuGet fronm 1.3.2 to 2.0.0, but apparently when I did that, Visual Studio didn't clean up my .csproj file perfectly.
So, I had to delete the superflous MSTest.TestAdapter.props highlighted in two places:
Near the top of the project file:
...and again at the bottom of the file:
Once I did that, my CI pipeline was able to build everything correctly again.
Some of you with sharp eyes may notice something funny w/the 1.3.2 of MSTest.TestAdapter shown above: it seems the path to the packages folder is off! But that would be a topic for a different thread (or maybe an alternate explanation to why your build pipeline is unhappy.. maybe just fix your path to packages).
My issue didn't occur on my development box but on the Azure Build Pipeline. I removed the offending props files as per the other answers but to no avail. Ultimately I had to add the Nuget restore step to my the Azure build pipeline and move it to the proper slot before the building:
I have no idea how I've done it but I've had the same error and I thought the files were here but they actually weren't... so anyone who has this issue double check the paths.
In my case the Packages folder was at the same level as the project file however it was looking for files in the parent directory. Nuget restore and Update-Package -reinstall
were not fixing anything.
When trying to install the NuGet Package RestSharp I get the error The path is not of a legal form and the package is not installed.
When installing from the console using Install-Package RestSharp, there are a lot of the following messages:
The item
C:\Users\myName\Source\Workspaces\Project\Solution\packages\RestSharp.105.1.0\lib\net35\RestSharp.dll
could not be found in your workspace, or you do not have permission to
access it.
This happens with the newly released Visual Studio 2015 (community edition).
Edit: If you have NuGet 3.0, then that's the problem. Just update NuGet and everything should work. The steps below apply to NuGet 3.0, which are painful and error prone. Don't go through such pain, choose the easy step, update your Nuget!
I updated to VS Express 2015 and since then i've been through some adventures.
TL;DR if you "disable" TFS (source control), you should be able to install the package. Then add the solution to source control again, but it caused me tons of problems.
So...
I see you have TFS. I have it too.
Also, I see you are getting the same error messages as me.
I tried to install LanguageExt (an awesome library for C# 6) and it failed when it tried to install one of its dependencies (System.Collections.Immutable).
If you want to go through all this things, please make a backup of your project folder.
This is what I did:
1 - Copied my solution folder to somewhere else.
2 - Opened the solution. VS smartly asked me to add it to source control, but I didn't want to.
3 - Tried to Install-Package LanguageExt
4 - Unexpected success!
5 - "Fine, let me just add it to the TFS source control again"
Here my journey started.
Since I have little experience with TFS, I got thousands and thousands of conflicts, files vanishing and appearing again, etc.
But after some work, I got it running.
And it was worth it.
But the solution isn't large, so, it was easy.
Had the same problem with the packages below, updated NuGet via "Tools -> Extensions and Updates -> Updates" to v.3.1.1.0 and now everything works again. Thanks!
Microsoft.Bcl
Google.Apis.Calendar.v3
RazorEngine
Sample error so more people can find this thread:
"Install-Package : The path is not of a legal form.
At line:1 char:16
+ Install-Package <<<< RazorEngine
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand"
Had a same problem with my VS 2015, I just added the reference via nuget by opening the same solution in VS 2013 and then reopened it back in VS 2015 for usual work.
I had this happen on version 3.5.0.1484 of the nuget package manager. In my case a merge from a dev branch altered a packages.config file to list a version of a package that was no longer present. Any attempt to use one of the package commands in the Package Manager Console after loading the solution failed with the The Path is not of a legal form. error. I ended up using the solution level gui to consolidate on the affected packages and that resolved the error. Likely I could have just reverted the packages.config file as well.
Please add an entry in package.config manully as given below and build the solution. This works for me.
I had the same issue in VS 2017, with another package (WPFLocalizeExtension).
The way to solve that was to delete .nuget folder from the project, then go to .csproj project file, and delete the following lines:
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<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>
After that (and after trying all the existing solutions into the whole world), I rebuilded the project nad the program runs succesful and works perfect.
It's really incredible the bugs of nugget repository....you need some kind of magic to solve in each specific case, it's terrible.
Hope this solution helps anyone.
I am trying to restore the missing nuget packages and it keeps giving me this Error:
An error occurred while trying to restore packages. Please try again.
Any experience solving this?
How can I find out what exactly is causing the error?
This is how I fix my issue:
First, I clear my Package Cache:
Second, I make sure I have the right path source and click the available package source:
Make sure you upgrade to the latest NuGet (http://docs.nuget.org/docs/start-here/installing-nuget).
Make sure you're doing package restore "The Right Way" http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html
That should resolve the issue.
If you don't want the package, just double-click your packages.config, find the line which refers to the package you want to get rid of, and delete that line.
Then, if you do want the package you could probably just redownload it using nuget and it'd probably resolve itself.
I had a similar issue with the Microsoft.Bcl.Build.1.0.14 NuGet package. My solution to this was to
Close Visual Studio
Remove the package folder with Explorer (or better only move it to another location)
Start Visual Studio
Go to the NuGet package manager and click Restore
I resolved the same issue by downloading the latest version of NuGet (really easy install, quick download): http://docs.nuget.org/docs/start-here/installing-nuget
(Definitely a beginner's answer here, but I'll leave it since I didn't find this anywhere else.) Make sure that nuget.org hasn't been unchecked from your package sources.
Tools. Options. Nuget package manager. Package sources. Ensure "nuget.org" is checked.
The problem in my case
In my case, we have developed our own NuGet packages. For some indescribable reason when I opened the solution, When I open solution, that has a previous version of NuGet packages that is deleted from origin or removed or unreachable for any reason. This make it unable to build the projects containing specific NuGet packages. I tried to install/reinstall/upgrade the NuGet package with out luck getting following error (see the image below), I did also try all possible answers here, and ensured the package was there, but no luck.
An error occurred while trying to restore packages: Unable to find version xxx..etc.
The solution for my case
Close your solution and find the path of the solution
Open all your projects .csproj files with notepad editor, that contain the packages that have the issue and remove all references that is shown in the error message, looks like this and save:
<Reference Include="Xxx, Version=30.0.0.16927, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Xxx.35.1.122605\lib\net461\Xxx.dll</HintPath>
</Reference>
In each folder where your .csproj is located, you find packages.config file, open it with notepad editor and remove all packages that is shown in the error message, looks like this and save:
<package id="Xxx" version="35.1.122605" targetFramework="net461" />
Start your solution, the error now should disappear, but you can not build because we have removed references and packages. So now you should be able to install your missing packages in fresh. When done build and all should work. Enjoy :)
I had similar issue, i found out it was due to my nuget cache.
Command to clear cache: dotnet nuget locals all --clear
After cache is cleared try restoring.
i fix this problem by moving the project folder to another one with less characters (local path was to long) i hope it helps some one
For me I cloned a solution (vs2015/NuGet3.4) that had a nuget dependency on a pre-release package that had been superceded. Nuget failed to restore the pre-release and wouldn't let me either uninstall or upgrade it. I frigged it by manually editting packages.config to target an older non-pre-release of the package, which I could then upgrade to the version I wanted. HTH
Just in case it helps someone else, I had this issue in a .NET Standard project where I had defined the target frameworks incorrectly:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.3;netstandard2.0;net45</TargetFramework>
</PropertyGroup>
...
When it should have been the plural TargetFrameworks (not TargetFramework):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.3;netstandard2.0;net45</TargetFrameworks>
</PropertyGroup>
...
For me non of those things mentioned above work.
I solved this issue by deleting packages.config in each project of my solution and then reinstalling all Nuget packages
In my case, I had another package source added which was like this.
I just removed this source from the NuGet package manager and rebuild the solution, it started working for me.
Go to TOOLS under OPTIONS select NuGet Package Manager
General, Select Everything
Package Source, Select all required Source
Hit OK. Done you must be good to go.