Nuget "already has a reference to" - visual-studio

Tests.Functional is selected from the Default project: drop down.
PM> install-package nunit
'NUnit 2.6.0.12054' already installed.
Tests.Functional already has a reference to 'NUnit 2.6.0.12054'.
Yet Nunit does not show up in References for Tests.Functional in the Solution Explorer. Tried reloading VS.Net (2010) and updating Nuget.
Am I missing something?

When running the solution under TFS, make sure the $(SolutionDir)\Packages\repositories.config file is checked out for edit.
Try the following:
Uninstall-Package NUnit -Force
Verify the Tests.Functional.csproj file (using notepad) no longer has any Reference to NUnit (if it still does, manually delete them, the project file probably got corrupted somehow).
Then run the following commandl:
Install-Package NUnit

I ran in to a similar issue trying to download the xunit framework when looking at the Entity Framework code. I worked around this by selecting a project to install to xunit to that didn't have the reference already, then just went in to manage and removed the reference to the project that didn't actually need it.
It appears that when a project references an assembly it doesn't have, nuget will see the reference and think that it doesn't need the assembly, even though it does. Simply adding the assembly to another project through nuget solves the issue. Not the most elegant solution, but it works.

Try the following in the Package Manager Console:
Uninstall-Package NUnit -Force
Then, go into your project directory and and manually remove NUnit references from your packages.config & .csproject files if any.
Now you can simply Install using:
Install-Package NUnit

Related

Unity keeps removing log4net from my Visual Studio project

I tried to install log4net for use in my Unity project with the following command :
Install-Package Unity.log4net
However, when I go back to the editor, then back to Visual Studio again, the log4net reference is removed, just like the Unity Editor had regenerated the project or something like that. The log4net reference no longer appears in the reference list and thus the log4net namespace can no longer be found.
I'm using Visual Studio 2017 Community Edition.
Has anyone experienced that and found a solution ? Thanks !
It seems like one cannot freely add references to a Unity project since Unity has to know about them. DLLs should be placed in a folder of the project called Plugins and then it works.
However it's weird that people are telling to use nuget packages. I'm assuming that must work somehow, but I don't know how. The solution above is dirty, but at least it works.
Unity projects require a special process to add NuGet packages. This is because when you open a project in Unity, its Visual Studio project files are regenerated, undoing necessary configurations. To add a package from NuGet to your Unity project you can check this doc from Microsoft: https://learn.microsoft.com/zh-cn/visualstudio/cross-platform/unity-scripting-upgrade?view=vs-2019

error MSB4062: The "Xamarin.Forms.Build.Tasks.GetTasksAbi" task could not be loaded from the assembly

After updating the packages "Xamarin.Forms" and "Xamarin.Forms.Maps" to latest version i.e "3.0.0.446417", the project will no longer build and I get this error:
C:\Users\[MyUser]\.nuget\packages\xamarin.forms\3.0.0.446417\build\netstandard2.0\Xamarin.Forms.targets(35,3):
error MSB4062: The "Xamarin.Forms.Build.Tasks.GetTasksAbi" task could not be loaded from the assembly
C:\Users\[MyUser]\.nuget\packages\xamarin.forms\3.0.0.446417\build\netstandard2.0\Xamarin.Forms.Build.Tasks.dll.
Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.
The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
The error refers to this place of the file Xamarin.Forms.Targets:
<XamlGTask
XamlFiles="#(EmbeddedResource)" Condition="'%(Extension)' == '.xaml' AND '$(DefaultLanguageSourceExtension)' == '.cs'"
Language = "$(Language)"
AssemblyName = "$(AssemblyName)"
OutputPath = "$(IntermediateOutputPath)">
<Output ItemName="FilesWrite" TaskParameter="GeneratedCodeFiles" />
<Output ItemName="Compile" TaskParameter="GeneratedCodeFiles" />
</XamlGTask>
And the XamlGTask is underlined with a warning which says:
Task 'XamlGTask' is not defined
What I've done so far is cleaning the whole solution, deleting the obj/bin folders and also clearing All Nuget Caches from Package Manager Settings but none of them helped.
error MSB4062: The “Xamarin.Forms.Build.Tasks.GetTasksAbi” task could not be loaded from the assembly
To resolve this issue, you should definitely make sure all projects reference the same version of the package Xamarin.Forms.
In your Solution Explorer right click on your solution node and select Manage NuGet Packages for solution.... Select the Consolidate tab and click on the Xamarin.Forms NuGet package, confirm all projects used the same version. If not, update all to the same version.
Besides, some one said that install .NET Framework 4.7.1 would help solve this issue, you can check if it helps.
Certified: https://forums.xamarin.com/discussion/comment/324869#Comment_324869
Note: If you could not install the .net framework 4.7.1 successfully, please try to update your Windows 10 to latest release. Thanks #Vahid.
Hope this helps.
Solution 1:
Sometimes it helps to kill MsBuild process with taskmanager. (Press ctrl+shift+Esc)
Solution 2:
Clean Solution
Close Visual Studio
Delete all obj/bin folders
(Sometimes a delete of packages folder is required)
Restart visual studio and rebuild
Tried all the above and failed. I mention that I use VS2017 v15.7.5.
If nothing works try this:
Close VS - all instances
Reopen VS without loading your solution
Go to Tools -> Options -> NuGet Package Manager -> Package Manager Settings -> NuGet Package Manager -> General -> Clear All NuGet Cache(s)
Load you solution and Build.
It worked for me!
I'm using VS 2017 with Xamarin Forms. These are the steps I took to resolve this error:
Make sure you're running same version of Xamarin.Forms for both Android and iOS
Close Solution
Open VS -> Tools -> Options -> Nuget Package Manager -> Clear NuGet Caches
Open Solution in Windows Explorer
Shift Delete vs folder
Shift Delete bin & obj folders in Android and iOS
Restart Computer
Once restarted, open VS and let it restore NuGet packages automatically (this may take time)
Clean solution
Rebuild solution
I had this issue and the solution was a pending restart for the windows update that had to be performed. very annoying.
I have faced the same issue recently, the simplest solution is to install .net framework 4.7.1, that's it. It's because 4.7.1 is required for netstandard2!
Reference: https://github.com/xamarin/Xamarin.Forms/issues/2667
Here is what worked for me:
Step 1: Close Visual Studio with the solution you are working on.
Step 2: Delete the .vs folder in your solution folder (The .vs folder is generally hidden)
Step 3: Re-open your solution with visual studio
Thats it.

Can't add a reference to EntityFramework in my unit test project

I have a new project happily using Entity Framework 5. After I added the edmx to the solution, it added a reference to EntityFramework version 5.
I created a unit test project, and I need to use something from the EntityFramework library. However, there is no reference to EntityFramework. When I go to Add Reference, I cannot find it anywhere in the list.
I've checked and my unit test is referencing .NET 4.5. Any idea why I can't add the reference?
Remove all the entries you have made to the web.config file. Just Right Click on your project name in the solution, Click on Manage Nuget Packages On your left hand Click on Online and on the right hand just put Entity Framework in the search box. Click on Install
this will do all the things automatically for you.
Answer is taken from: EntityFramework 5 Install fails in VS 2012
I had the same problem with a new application. I opened the Package Manager Console and used install-package EntityFramework, which installed version 6 without issue.
Just Adding System.Data.Entity might not enough;
because by this you are trying to referencing something that has not been installed yet.
this issue can be resolved by installing EntityFramework.
So to do this :
Go to Solution Explorer
Right Click on Your Project Name
Select "Manage NuGet packages"
Now Install the Entity Framework.
You need to add a reference to "System.Data.Entity" dll at References folder of your Unit Test project.

Nuget: Set one project in solution as unmanaged by Nuget?

First off, let me start by saying that Nuget is awesome. I love it. That being said, there is one thing about it that I have just discovered which is really getting very annoying.
We have an in-house framework which we use for almost all of our projects. So, I recently created a Visual Studio project template for it, along with the VSIX.. had a few problems along the way due to Nuget.. it wouldn't create the new project from a template when the template was referencing the framework.. because the framework was using Nuget and it couldn't find the nuget folders in the new project created from the template. So, solution was to remove nuget from the framework project and only use Nuget for the other projects (anything but the framework). Okay, great.. that solves the problem!
However, now with every Nuget managed project that I open, it automatically adds these 2 lines back into the .csproj of the framework:
<RestorePackages>true</RestorePackages>
and
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
This is frustrating because we now need to either stop using Nuget altogether OR to keep removing these lines from our framework's .csproj file every time we want to rebuild the template.
Is there any way I can tell Nuget to ignore one project in the solution? In my case, to ignore the framework project...
With a suggestion from Nailuj and also from what I found here: http://samritchie.net/2012/09/17/nuget-packages-in-vs2012-templates/, I tried something that I thought would work, but it didn't serve my needs; that method is just for including the packages in with the new project, which for me is not helpful and doesn't solve the problem (error about missing .nuget targets folders). So, I played with it a bit and came up with something that is not ideal, but is acceptable:
Remove anything and everything to do with Nuget from the project which is to serve as a template. This then causes a problem with the referenced framework, because the framework project is expecting to be managed by Nuget and from this solution it's not, so error occurs... so:
Remove the framework project from the solution and only reference the DLL so it will build, but not complain about missing nuget folders
Rebuild
Export to template
Build VSIX using exported template
Install template
Create a new project from the newly installed template
Enable Nuget package restore on solution of new project
Open Package Manager Console
Notice message about missing packages and agree to download and install them (about 1 minute)
Remove framework DLL reference and replace with actual project (Right-click, Add Existing Project)
Rebuild and run
Celebrate!
I hope this helps anyone else who may find themselves in this predicament. If anyone has a better idea, please let me know. The bounty is still open for another 6 days, so I won't mark this as answer yet.

A way to clean up Nuget packages in the csproj file?

As I add and remove references sometimes I don't always "uninstall" a package which appears like a reference. So it remains "installed" in the Nuget package explorer. It seem like I could really use something that cleans up the .csproj and the packages.config file -- is there something that does this?
This would be useful for both Visual Studio (VS) 2010 and VS 2012.
Uninstalling a package should be done as an explicit gesture.
If you want to know if a particular reference is part of a package, you can check the Path of the reference. If the hint path is something like "..\Packages\.." , you will know that the reference is part of a package.
I'm also looking for a tool to help with cleaning up the packages and at least identify unused Nuget packages for me. For now the manual way to check that a package is used or not is to uninstall the package and compile the project. If everything is still passing that means the package is not used. If things failed you can simply revert the changes in your source control system. You will need to repeat these steps for each package installed in your Visual Studio solution.

Resources