I converted a .NET Framework 4.7.2 project from packages.config to PackageReferences format by right clicking the packages.config file within VS 2019.
Since then Visual Studio shows blue icons of a NuGet package which I uninstalled from the project in the References node. What is truly weird is that without this package the build should fail as it is used within the code, but the build succeeds!
There are no packagereference to this NuGet package in the .csproj
file.
There is no packages.config file in the project directory
I deleted the .vs folder and the older packages folder
Restarted Visual Studio
Problem Remains
uninstall-package command fired within Visual Studio says the
package is not installed.
Yet the Reference (Blue Icon) is shown and the project builds!
Question
How do I completely remove this package from the project?
How do I stop Visual Studio from referencing this package for now?
===============================
If your project does not reference any other projects or just reference a project which does not install the same nuget package, I think the issue is related to your project itself or VS environment.
And in this situation, it is quite strange that the blue icon of the nuget package still stays on the solution explorer while you have already uninstalled the nuget package.
Please try the following suggestions:
1) disable any third party extensions under Extensions-->Manage Extensions-->Installed
2) clean nuget caches and reset vs settings under Tools-->Import and Export settings-->Reset all settings
3) then close VS, delete cache files under
C:\Users\xxx(current user)\AppData\Local\Microsoft\VisualStudio\16.0_xxx\ComponentModelCache
and also delete .vs hidden folder, bin and obj folder.
4) then restart VS to test whether the issue persists.
Besides, you could use devenv /safemode to start a clean and initial VS and then test your project.
=================================
If your situation is this one:
Your project B has referenced a project called Project A while A has also installed the same nuget package. And project A uses PackageReference nuget management format.
Although you have uninstall the nuget package on Project B, your obj folder still has files like project.assert.json,xxx.nuget.g.props which is a feature of PackageReference. Due to it, the nuget package management format of Project B is the same as the Project A and will transmit the dll from the Project A into Project B so that you can use the dll in the project B.
And that delete .vs hidden folder will remove the nuget package format PackageReference of Project B since you already uninstall all the nuget packages on Project B but the PackageReference content of obj folder still exist.
So you should close VS, delete .vs hidden folder, bin and obj folder of the Project B at the same time.
Note: Rebuild and Clean will not delete the previous restore files.
If this does not work, I think you have written this xml node under B.csproj file:
<PropertyGroup>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
So you should check in your project B carefully and it will still restore the files project.assert.json,xxx.nuget.g.props,.... as PackageReference.
Therefore, if you have, delete this node, also delete .vs hidden folder, bin and obj folder.
Related
I'm trying to use Microsoft.CSharp to run C# files but I get two errors:
the errors
I'm using visual studio and unity. I used the NuGet package manager to install Microsoft.CSharp, System.CodeDom, and System.CodeDom.Compiler. I'm using all of them at the top of the file.
I don't really know anything about packages and I've never had to install one; I would just put "using packagename" at the top of my code and it worked, so I'm sorry if this is a simple fix.
I tried reinstalling all the packages and nothing changed.
I tried closing and reopening visual studio and nothing changed.
When I installed the NuGet packages it created a packages folder, app.config, and packages.config. I tried uninstalling the packages, deleting the folder and the configs, and then reinstalling the packages. It recreated the folder and configs and nothing changed.
I tried including the packages folder in the project and nothing changed.
I have other (working) packages that I didn't have to install so maybe I need to somehow install the new packages wherever those pre-existing packages are located. But idk how to do that or if it would even help.
I have a question so that I can better understand NuGet packages, packages.config and the .csproj file.
It is my understanding that the setting in the NuGet Package Manager >> General for default package management format determines if your project uses packages.config or the .csproj file for resolving and restoring packages.
In my project we have selected Packages.config.
No problem it compiles and runs. So I decided to test if it would run without the reference for a dll in the .csproj file, as it is my understanding it does not use or need this. This is an incorrect assumption as though the package is in the packages.config file, when I removed the reference in the .csproj file there was an error in my project and the project would not compile.
I also noticed that if the dll is not in the references in the Solution Explorer that it fails to compile as well I( I assume these are the .csproj references).
So I am not clear on the role of the .csproj file for a Packages.config Management format for NuGet packages and the references in Solution Explorer.
The difference is on how you manage your NuGet references.
Before VS2017 the information what NuGet packages to be used during assembly was stored in files packages.config.
Since VS2017 there is a new option called package references which stores this information in the project (.csproj) file.
https://devblogs.microsoft.com/nuget/migrate-packages-config-to-package-reference/
Before VS2017 and .NET Core, NuGet was not deeply integrated into MSBuild so it needed a separate mechanism to list dependencies in a project: packages.config or project.json. Using Visual Studio solution explorer's References context menu, developer adds .csproj references to restored packages in a solution-wide folder managed by NuGet.
The reference added to the project file .csproj by Visual Studio looks like this:
<Reference Include="EntityFramework, Version=6.0.0.0"><HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath></Reference>
Starting with VS2017 and .NET Core, NuGet becomes a first class citizen in MSBuild. NuGet package dependencies are now listed as PackageReference in the SDK-style project file .csproj
A reference now looks like this:
<PackageReference Include="EntityFramework" Version="6.4.4" />
I have a solution which contains multiple c# projects. Some of these projects have nuget dlls as references.
By default nuget pulls all the dlls to a folder called packages in the solution folder (The dlls may depend on other nuget dlls so nuget pulls them too to the packages folder). This works fine for a normal build.
Now I want to deploy my application where all the .dlls are present in a single folder. What is the best way to collect all the nuget dlls into that folder.
Note: While adding Nuget references to a project, CopyLocal is set to true by default, so the nuget dlls are copied into the bin folder of that project. So, I can pull those dlls form there. But I am not sure how to pull the second order dependencies (Other nuget dlls on which the nuget dlls I reference depend on) as they are not copied to the bin folder of project.
But I am not sure how to pull the second order dependencies(Other nuget dlls on which the nuget dlls I reference depend on) as they are not copied to the bin folder of projec
According to the document Dependency resolution:
Any time a package is installed or reinstalled, which includes being
installed as part of a restore process, NuGet also installs any
additional packages on which that first package depends.
Those immediate dependencies might then also have dependencies on
their own, which can continue to an arbitrary depth.
So, when we install one nuget package to our project, NuGet will add the nuget package dll and its dependencies to the project. Besides, NuGet will set the property of CopyLocal to True by default for the dependencies. In this case, all the dependencies will also be copied to the bin folder.
For example, when we install the nuget package Microsoft.Owin to the Asp.net application project, its dependency owin will also be installed to the project by default and the property of CopyLocal is also set to True by default. After installation complete, the dependency owin will copied to the bin folder.
So, to resolve this issue, please make sure the dependencies of the installed nuget package are also added to the project, and check if the property of CopyLocal is set to True.
I have created a new web site using Visual Studio 2017. The target framework for this site is NetCoreApp 1.1. As this is an MVC project, it references a number of Microsoft and third-party dlls from Nuget. I also have a data project that I created as a library. It is Netstandard1.6. When I build the solution, none of the dlls from the Nuget packages are copied to the bin folder. This causes the app to crash with a FileNotFound exception when attempting to debug it. The project references are being copied correctly, so it appears to only be a problem with Nuget packages. As a workaround, I can publish the project and copy that output to the bin folder, but I shouldn't have to do that, should I?
.NET Core uses the generated .deps.json file in the output to resolve assemblies, so it avoids copying the files unnecessarily during the build.
However if some assemblies try to look for other assemblies in the output directory or the files referenced in the deps.json file cannot be accessed (e.g. testing build output in IIS), you can add this to a <PropertyGroup> element in your csproj file to cause the NuGet assemblies to be copied to the output directory:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
This 'CopyLocalLockFileAssemblies' doesn't do anything on my end. The only way I found to get the content of the 'runtime' folder in my output is to use 'Publish'. This is not a solution to locally debug an application.
Edit :
Adding the Runtime IDentifiers to the project file seems to do it for me.
Also, .NET Core 3.0 fixes the issue but it is only in Preview.
I have created a web application project. While developing my application, I have installed some packages from NuGet and yet they still there in my project. But when I copy my project to another computer and try to run the project, there are many errors occurred because all references are marked with yellow alerts.
I open the project with file .sln
When I run the project, it generated a lot of error because it cannot find the libraries.
As Abhay Saraf's request, I provide the link to download .csproj section: http://www.hellomeo.net/Umbraco/EmployeeLeaveManagement.zip
First, you need to check the packages.config file in your project to confirm all packages are listed in this file. Then please check your Visual Studio settings (Tools -> Options -> NuGet Package Manager -> General), the options under Package Restore are all checked as below screenshot.
If above options are checked but the packages still not restore automatically, please use following ways to restore packages for entire solution.
Open Package Manager Console window from View -> Other Windows -> Package Manager Console.
Type command “Update-Package -reinstall” to reinstall all packages in your current solution which will based on the packages that listed in the packages.config file.
Right-click on one of the missing references, choose Properties and see what the Path is set to. Is the Path correct?
Run dnu restore from the Package Manager Console