Reference not updated after install - c#

I have recently upgraded my reference packages
Microsoft.Aspnet.Mvc from 4.0.0 to 5.0.0,
Newtonsoft.Json to 6.0.3,
Microsoft.Aspnet.WebApi to 5.0.0
And I installed it using NuGet Package Manager Console in Visual Studio 2013. But when I check the version of the references in the solutions explorer, I still see the older version for MVC reference. The other references have been updated.
In the .csproj file I see the Reference include for System.Web.Mvc mentions version 4.0.0.0 but HintPath is for 5.0.0.
I tried the following:
Deleted the packages directory from Windows explorer
Updated package through Package Manager Console, but the problem still persists.
Could someone help me with this?
Edit: Adding one of the reference tags
<Reference Include="System.Web.Mvc, Version=4.0.0, Culture=neutral, PublicKeyToken=12345, processorArchitecture=MSIL">
<SpecificVersion>false</SpecificVersion>
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.0.0\lib\net45\System.Web.Mvc.dll</HintPath>
</Reference>
As you can see, the Version in the reference is 4.0.0 and that in the hint path is 5.0.0. 4.0.0 is the version I see in the solution explorer.
I also set the specific version tags to True for all the references in question and built the code, but again, when I look at the properties of the reference in solution explorer, I see 4.0.0.
Edit 2: I deleted the reference from the solutions explorer, then References >Add References > Browse> Selected the latest downloaded Reference dll from package directory. The version in reference manager is 5.0.11001.0
Then I looked at the properties of the added reference. It still is 4.0.0

Related

How can we use managed nuget packages in c++/cli project

I want to consume managed nuget package in c++/cli project. Is there a way to do that?
For example my scenario is almost like this:
I have created a C# project(MainProject) and added EntityFramework nuget package to that project.
I have created one more C# project(TestCSProject) and added MainProject as reference to that project. Then automatically in references entityframework is also added
I have created one C++/CLI project(TestCLIProject) and added MainProject as reference to that project so that I want to see whether I can use entityframework.
But that didnt happened.
So I want to know how can I use managed nuget package in c++/cli project
C++/CLI project can use nuget packages using packages.config (in VS2019 still there is no PackageReference support for C++, PackageReference for NuGet packages in C++ projects). As pointed in the comments, C++/CLI should be used for interop with native code only. Anyway there may be a need sometime to use nuget packages here.
In Visual Studio 2019 the following worked for me for a C++ project referencing .Net Framework:
Go to package manager console: Tools -> NuGet Package Manager -> Package Manager Console. Then install nuget package(s) (instruction from Microsoft). E.g. EF nuget installation could be like:
Install-Package EntityFramework -Version 6.4.4 -ProjectName TestCLIProject
After nuget installation a packages.config file will be created in the project's folder and added to the project. E.g. after EF nuget installation packages.config could be like:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.4.4" targetFramework="native" />
</packages>
Add reference(s) to dll(s) from the nuget. Project -> Add Reference... -> Browse... -> locate solution's folder -> go to packages folder -> go to nuget's folder -> locate dll(s)
For example for EF this resulted as .vcxproj was updated with:
<Reference Include="EntityFramework">
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer">
<HintPath>..\packages\EntityFramework.6.4.4\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
Project is ready for build. If Visual Studio has opted out Tools -> Options -> NuGet Package Manager -> Automatically check for missing packages during build in Visual Studio, then nugets could be manually restored e.g. in Package Manager Console with Update-Package command.
With the newest Version of VS2022 (Visual Studio 2022 version 17.3) you can now as well use PackageReference in your C++/CLI project. Just make sure you have added
<EnableManagedPackageReferenceSupport>true</EnableManagedPackageReferenceSupport>
to the PropertyGroup with Label="Globals" in your .vcxproj file. Furthermore please be aware that your C++/CLI project must be targeting .NET Core or .NET 5+. As you can read in the Release notes this doesn't work (and neither is it planned to be supported in the future) for C++/CLI projects targeting .NET Framework.
With this enabled you can now also use the NuGet Package Manager by
In Solution Explorer, right-click "References" and
choose "Manage NuGet Packages"
just like it is described in the Microsoft documentation.

Could not load file or assembly 'System.Security.Principal.Windows'

Solution has compiled successfully, but after I added an existing class file to the project, this error appeared:
The specified task executable "csc.exe" could not be run. Could not
load file or assembly 'System.Security.Principal.Windows,
Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file
specified. MvcApplicationRegister
I installed System.Security.Principal.Windows package By NuGet, but error still appears.
None of the previous answers worked for me.
The problem was that I didn't have the .NET Compiler Platform SDK installed.
To solve, open Visual Studio Installer, choose "Modify", and under the "Invididual Component" tab, check the .NET Compiler Platform SDK, and confirm your changes by clicking "Modify".
After I installed it and reopened Visual Studio, the problem is gone.
I had the same issue after I upgraded Microsoft.Net.Compiler from 2.8.2 to 2.9.0.
After I downgraded to 2.8.2 projects compiled without any errors.
Had this same issue and resolved it.
In a 3 project solution MVC controller (Web,Business,Data)
Caused by the Microsoft.Net.Compiler 2.9.0 being installed on the Web project but not the other projects.
To resolve:
Right click the solution.
Manage NuGet Packages.
Installed > Search for the compiler
Ensure it is the same version and it is installed on all projects in your solution
Once installed my solution built successfully
If you are using Microsoft.CodeDom.Providers.DotNetCompilerPlatform you can upgrade to 2.x and then remove Microsoft.Net.Compilers as it's no longer needed. That solved it for me, however I couldn't even build the solution in the first place. It was still complaining about System.Security.Principal.Windows though, I could also solve it by referencing System.Security as an assembly. It's not recommended though.
Close down all instances of Visual Studio. Then reopen the solution and rebuild.
I uninstalled both Microsoft.CodeDom.Providers.DotNetCompilerPlatform and Microsoft.Net.Compilers and everything now works.
In my case I could go from Microsoft.Net.Compilers 2.4.0 to Microsoft.Net.Compilers 2.10.0. No need to use Microsoft.Net.Compilers 2.8.2.
I do not like removing packages without first understanding what I'm removing. I faced the same problem with my solution.
I discovered that 1 of the many projects was using the Microsoft.Net.Compilers NuGet package - let's call it Project ABC. A Unit Test project was referencing that Project ABC, but not the Microsoft.Net.Compilers NuGet package.
I simply referenced the Microsoft.Net.Compilers NuGet package from my Unit Test project, and the problem has now gone away.
Updating Microsoft.CodeDom.Providers.DotNetCompilerPlatform and deleting Microsoft.Net.Compilers worked for me.
I had the same issue here using 'System.Security.Principal.Windows' version 4.7.0. For some reason when I installed the nuget package it was referecing the dll from the folder: C:\Users\{your-user}\.nuget\packages\system.security.principal.windows\4.7.0\ref\netstandard2.0\System.Security.Principal.Windows.dll then I changed to reference the dll from the folder C:\Users\{your-user}\.nuget\packages\system.security.principal.windows\4.7.0\lib\netstandard2.0\System.Security.Principal.Windows.dll and everything worked just fine! So I copied the dll from the lib folder to my project and made a direct reference.

NuGet, Packages.config, .csproj and references

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" />

Xamarin in VS - Unable to install Android Support v4

I installed Visual Studio 2015 to try out Xamarin that comes with the community version, but I have not been able to open a single project. I have downloaded a few projects from GitHub that I want to try out, but they all get the same error. First, it says I am missing a reference/assembly, and I figured this was the Xamarin.Android.Support.v4. So I downloaded this from Xamarin's website and added it to the project. This somewhat worked, however every time I try to build my project, I get an error:
NuGet Package restore failed for project AndroidAltBeaconLibrary.Sample: Unable to find version '21.0.3' of package 'Xamarin.Android.Support.v4'.
This error seems to haunt me whatever I try to do. When I open my NuGet manager, I am not able to do anything, as this error pops up here as well (I wanted to try remove the NuGet and add it again). It just says Xamarin.Android.Support.v4 is installed (but not available in this source) regardless of if I remove it from References.
Does anyone have any tips of what to do??
Edit: I forgot to mention, the version I downloaded is 23.1.1.1
Edit 2: Using the install command does not work in the projects. An error says it needs to restore NuGet packages first, however it is not able to do this either. In a blank project, it is not able to find this NuGet (neither 23.1.1.1 nor 21.0.3.. In fact, when I open NuGet manager, it is not able to find any NuGets at all in the Browse Tab. Is my VS just messed up? Should I reinstall the whole thing??
I have trouble restoring Xamarin.Android.Support nugets too. This solved my issue:
1) allow nuget restore on build (Tools > NuGet Package Manager > Package Manager Settings)
2) remove the reference from .csproj file:
<Reference Include="Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Xamarin.Android.Support.v4.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll</HintPath>
<Private>True</Private>
</Reference>
3) rebuild all (ignore errors, restore will still work)
4) put the reference back to .csproj file
5) rebuild and it should be OK
You need to use the specific 21.0.3 version of Xamarin.Android.Support.v4, which Xamarin uses.
Install it from NuGet

Nuget references in Visual Studio

I had the solution in VisualStudio 2012 with some nugets packages installed with chosen version by me. After migrating to VisualStudio 2013 I find out that packages are referenced from hard drive instead of nuget.
In nuget I installed WindowsAzure.Storage, version 3.1.0.1.
After migration there is WindowsAzure.Storage referenced from hard drive, version 3.0.3.0.
In project .csproj file I have:
<Reference Include="Microsoft.WindowsAzure.Storage, Version=3.1.0.1, ...>
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\WindowsAzure.Storage.3.1.0.1\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
</Reference>
I can see that nuget didn't set SpecificVersion to true, so VisualStudio is using version it found on hard drive instead of downloading one from nuget.
Is there any way to change it without some nasty hacks so it will always download dlls from nuget if package was installed by nuget.
How about restoring all your packag:
NuGet Package Restore

Categories