Nuget Packages not working correctly in Visual Studio - c#

I am writing a Windows Phone app, at the beggining using VS 2010 Express for windows phone. Then I installed VS 2012 and i made a desktop app which consumed JSON/REST service using RestSharp. Due to lack of support for plugins in Express version, i got full VS 2010 Ultimate and installed Nuget. When I create a win phone library project, and i add a RestSharp package, it shows in References, but i cannot access any of it's classes (and using RestSharp is underlined in red color). Also, when i Remove it and add again from Add Reference i get an Incompatible reference error window:
RestSharp.WindowsPhone, Version=103.2.0.0, Culture=neutral, PublicKeyToken=null" is incompatible with
Windows Phone 7.1
In order to add it yourself you should to change the project's terget to a compatible framework first.
It also appears if i change the target to WP 7.0.
Has anyone solved similar problem?

In my case this was because there was a packages.config file in the project folder but not in the solution. This was why I could not add the reference again properly. Delete this file from the physical disk, and re-run your Install-Package command. It should add this correctly now.

Are you using source control?
The it might be possible that you have not yet set the solution to enable package restore (NuGet documentation).
Right click on the Solution node in Solution Explorer and select
Enable NuGet Package Restore.
After that Solution Explorer will contain a few items more and there will be a new folder packages that was automatically added to your solution folder. You will need this folder to add to your version control because it will contain your installed NuGet packages.
That's it.
If you want to know more, here's more details on what it (automatically) does for you:
It added a solution folder named .nuget containing NuGet.exe and a
NuGet.targets MsBuild file. It also changed every project in the
solution to import the NuGet.targets MsBuild task.
With this in place, any time a project is compiled, the build task
will look at each project's packages.config file and for each package
in that file, ensure that the corresponding package exists within the
packages folder. For any missing package, the build task will download
and unpack the package.
In the restore scenario, NuGet will grab the exact version when
restoring a package. It will not perform any upgrades.
Additionally, if you have the latest NuGet version installed, will now find a new option unter Tools -> Options... -> Package Manager -> General -> Allow NuGet to download missing packages during build that I would also suggest to use.
The name says it all. If the solution is configured to use a certain NuGet package but the package is not yet installed on your development machine, NuGet will download it automatically for you when you do your next build.

Related

Emgu error when trying to install emgu.CV.runtime.windows in VC# 2017

I'm trying to install emgu.CV.runtime.windows from within Visual Studio 2017, and installing by the recommeded method of right-clicking references and installing via NuGet.
However I am getting the error below.
Could not install package 'Emgu.runtime.windows.msvc.rt.x64 19.28.29336'. You are trying to install this package into a project that targets .NETFramework,Version=v4.7.2, but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
According to the package information, its dependencies are
enter code here.NetStandardVersion=2.0
enter code here.Engu.CV (> 4.5.1 && < 4.5.2)
enter code here.Engu.runtime.windows.msvc.rt.x86 (= 19.28.29336)
enter code here.Engu.runtime.windows.msvc.rt.x64 (= 19.28.29336)
I checked and c:\windows\Microsoft.NET\Framework contains a folder for v2.0.50727, so it seem .net 2.0 is installed (as is v3.0, v3.5, v4.0.30319)
I have emgu.CV 4.5.1.4349 installed.
I need this library so that I can have the enter code herebitmap.ToImage<Bgr, byte>(); function.
Why am I getting this error?
Any help would be greatly appreciated.
The solution is migrating from package.config to package references for every project you have. Simply right click on package.config and click "migrate package.config to PackageReference".
Then, install the runtime package again and it will work.
For the new Emgu Nuget package you do need to use PackageReference instead of the traditional package.config.
What worked for me on Visual Studio 2017:
Uninstall all NuGet Packages [This removes the package.config file]
Go to Tools --> Options --> NuGet Package Manager --> General
Change the default package management format to "PackageReference"
Check "allow format selection on first package install"
Click OK
Install Emgu.CV, Emgu.CV.Bitmap, Emgu.CV.UI and Emgu.CV.runtime.windows
These Emgu packages should now appear under your references and you should not see a package.config file.
Nuget Options Image
I encountered the same error. I don't know why we're getting it, but I was able to find a workaround.
Visit the nuget page for the package.
Click "Download Package" to download the nuget package directly.
Open the downloaded file using your archive utility of choice and navigate to the "\runtimes\win-x64\native" folder.
Copy both dll files into the output directory of your project.
After doing this, my code executed without error. Make sure to install emgu.CV.Bitmap as well.
I changed my projects Target Framework to ".NET Framework 4.6" and then went to "Manage NuGet Packages", selected "Browse", typed in "emgu.cv.runtime" then installed version 4.5.1.4349 and it worked.
Here is how I solved it,
1- downgrade .Net framework to 4.6 from project properties
2- Uninstall Emgu.CV and related ones (you will see which ones needed to be uninstalled in Errors List)
3- Install Emgu.CV.runtime.windows from Solution Nuget Manager ( it should install fine now)
3- upgrade .Net framework to 4.8
4- install Emgu.CV 4.5.1 (latest)
5- install Emgu.CV.UI 4.5.1 (Emgu.CV.Bitmwp was installed automatically for me)
and that's it, now you can use bitmap.ToImage<Bgr,Byte>(), note that the Image<Bgr,byte>(bitmap) doesn't work anymore.

C# Windows forms Application Reference error in release

I have my windows forms application with WindowsAPICodePack but i don't know where should I put the package in the release folder, and without it the program just gives me an error (it's in Hungarian so I don't think anybody can understand, but it said that it can't find the windowsAPICodePack, the version number, culture and publickeytoken) on another PC, on mine it works.
Depending on if your application is using a packages.config file to manage packages or if your project is using package references (PackageReference) will determine path to solution.
When a package is installed it records the package identifier and version into the project file or packages.config file in your solution workspace.
If using a package.config to mange packages then ensure your packages are getting installed in the location as expected, possibly clearing the cache will help to ensure proper version is installed.
find out the packages folder where your application is trying to load the references.
Possibly config binding redirects.
Clear you package cache and reinstall. use the package manager ui for your ‘debug’ and ‘release’ MSBuild configs to ensure the package is being referenced correctly.
Verify your nuget.xml settings file for locations of packages
Read all the version or property values to use for your application. Ensure you are configuring the release target as expected.
Here are some links to help you config the correct setup for your approach:
Package reference via project files
if using - Packages.config settings
Config setting for Nuget
NuGet settings
Note: for simplicity if this is just a school project then just remove all NuGet packages references and find the dll . Then just add reference to dll and check the property to include in output . This will give you a simple folder with all the files needed to run your app from pen-drive

Visual Studio auto restores dll packages

In the company I work, inside every solution we have one folder packages, which contains all dll dependencies. This folder is not in repository with the rest of the solution.
Every time I build one project, all files inside folder packages are restored and any missing dlls appear again. This happens in the beginning of the build, no matter if the build succeeds of fails. Even if the project has no dll dependencies, any missing dlls in packages are restored.
I suspect it is a setting in msbuild but I cannot find it. Does anyone know where it might be or if there is a place with msbuild *.targets files?
thanks for any help
This is because Visual Studio restores packages defined in the packages.config files.
You can control this behaviour in Visual Studio in options:
From the MS Docs regarding regarding Nuget:
MSBuild: use the msbuild -t:restore command, which restores packages
packages listed in the project file (PackageReference only). Available
only in NuGet 4.x+ and MSBuild 15.1+, which are included with Visual
Studio 2017. nuget restore and dotnet restore both use this command
for applicable projects.
Further down, there's quite a bit about enabling/disabling and modifying this behavior in a variety of ways.
Allow NuGet to download missing packages: controls all forms of
package restore by changing the packageRestore/enabled setting in the
NuGet.Config file as shown below (%AppData%\NuGet\NuGet.Config on
Windows, ~/.nuget/NuGet/NuGet.Config on Mac/Linux). In Visual Studio,
this setting allows the Restore NuGet Packages command on the
solution's context menu to work.
Appearing to be more to your issue:
Automatically check for missing packages during build in Visual
Studio: controls automatic restore by changing the
packageRestore/automatic setting in the NuGet.Config file as shown
below (%AppData%\NuGet\NuGet.Config on Windows,
~/.nuget/NuGet/NuGet.Config on Mac/Linux). When this option is set,
running a build from Visual Studio automatically restores any missing
packages. The option does not affect builds run from the command line
using MSBuild.

Adding a NuGet package to packages.config not associated with a Visual Studio project

In the limited amount of time I've worked with NuGet, the packages.config files I've encountered have all been associated with a Visual Studio project. I've just found one that seems to not be associated with a project (in this case a C# project). Rather, it's purpose appears to be to gather tools that are required to successfully complete a build of the solution the project is a component of (i.e. the NuGet packages in the packages.config file are never referenced directly in a .cs file).
I know I can open the packages.config in a text editor and add a new package to it. However, that seems to run contrary to the idea of NuGet as I understand it, and I'm not sure if adding an entry into packages.config manually won't create problems down the road.
What is the best way to add a new NuGet package to a packages.config file that's not associated with a Visual Studio project like this? The Microsoft docs I've found so far all seem to mention a corresponding VS project ( see https://learn.microsoft.com/en-us/nuget/consume-packages/ways-to-install-a-package)
Using Visual Studio to manage NuGet references for .NET projects that use packages.config is useful/important because of all the extra things that need to happen on "install". But for .NET projects that use PackageReference, using Visual Studio is just a minor convenience because it will restore the packages at the same time as changing the XML. There is no Visual Studio UI for isolated packages.config files
So, there's no problems editing your packages.config file with a text editor. You'll just need to run nuget.exe restore yourself (or more likely it's part of a build script). In fact, the NuGet team have one themselves as part of their build.

Nuget Cant install Xamarin.Android.Support.Animated.Vector.Drawable 27.0.2

I am running into an issue when updating installed Nuget packages in my Xamarin.Android project. When running the updates, I get the following error:
Could not install package 'Xamarin.Android.Support.Animated.Vector.Drawable
27.0.2'. You are trying to install this package into a project that targets
'MonoAndroid,Version=v8.0', but the package does not contain any assembly
references or content files that are compatible with that framework. For
more information, contact the package author.
A quick google search yielded several results with similar answers like the one found in this question. It seemed that I simply needed to make sure my Target Framework was set high enough.
Following the instructions found here I set out to change the Target Framework in Visual Studio 2017, however I found that it was already set to use 8.0.
Is there another step that I am missing in order to get these packages to update?
As Jon Douglas mentioned, API 27 actually requires Android 8.1. If you don't have the option to switch to 8.1 you will need to update Visual Studio. Once that is done, you should be able to install the 8.1 SDK via the Android SDK manager (Tools -> Android -> Android SDK Manager).
After the SDK is installed, you can set your Target Framework to 8.1 and update the Nuget packages.
you have to change your Mono.Android.dll Version to 8.1,
When I tried updating this library recently, I found there were some old lingering references in the csproj file, causing conflicts.
To resolve,
Unload the project (right click the project > Unload Project)
Open the csproj (right click the project > Edit xxx.csproj)
Remove all references to 'old' targets (for example, the whole reference tag to old libraries)
There may also be Import tags that need removing
On re-loading the project (right click > Reload Project), I was able to update that library.
In my case, I had Visual Studio 2017 with the most recent SDK version which included Android 8.1.
Even after changing all 3 Android target versions from the project properties to 8.1, the csproj was still showing a TargetFrameworkVersion of 7.1 as follows:
<TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
I manually changed that to 8.1
<TargetFrameworkVersion>v8.1</TargetFrameworkVersion>
It will be interesting to find out if the minimum Android version still needs to be at 8.1 though.
and was then able to update the Nuget packages.

Categories

Resources