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
Related
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.
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
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" />
One of my project solution is working fine on a system where I have installed VS 2013. But When I open the same project on another system in VS 2015 it is giving this reference error:
Error CS1703 Multiple assemblies with equivalent identity have been imported: 'D:\src\packages\Microsoft.Bcl.1.1.10\lib\net40\System.IO.dll' and 'C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades\System.IO.dll'. Remove one of the duplicate references.
The project file is referencing the package file, but when it opens in VS it auto converts to Framework library path. I can't uninstall the BCL package because it is a dependency for other packages.
Edit:
Why does the solution build fine in one version of Visual Studio but it gives the multiple assemblies error in another version?
Is there a way to resolve this issue so that it works in different versions?
I also have this issue however his solution builds perfectly in VS 2017 but it cannot build on VS 2015.
This error usually appears when a NuGet package has invalid dependencies, but this is not the case as everything works well in other versions of Visual Studio.
First you can force reinstall all NuGet packages. That can be done by opening the Package Manager Console and typing:
Update-Package -reinstall
Second most common solution to this problem is to ensure Visual Studio is updated to the latest version (Visual Studio 2015 Update 3 in this case). If that doesn't help, please try reinstalling Visual Studio completely on that device. Finally - you can try to install Visual Studio 2015 on another PC to verify if this is actually a problem of that version, or a PC-specific issue.
This error occurs when a non-portable library references to a portable library then the build system adds a facade assemblies. [1]
Try to remove following references:
<Reference Include="System.IO">
<HintPath>..\packages\System.IO.4.0.10-beta-22516\lib\net45\System.IO.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System.Text.Encoding">
<HintPath>..\packages\System.Text.Encoding.4.0.10-beta-22516\lib\net45\System.Text.Encoding.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks">
<HintPath>..\packages\System.Threading.Tasks.4.0.10-beta-22516\lib\net45\System.Threading.Tasks.dll</HintPath>
<Private>True</Private>
</Reference>
If you are using a common assembly across multiple projects and want to ensure they are using the same version, I recommend installing that version into the Global Assembly Cache.
Then that version from the GAC will be available from the references dialog.
Use that same dialog for the references across assemblies.
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