Set required RunTime in nuget package - xamarin

I'm creating two Nuget package using the official UI tool (a package contains .Net related utilities, the other contains Xamarin.Android stuff)https://docs.nuget.org/create/using-a-gui-to-build-packages
Now I need to set the minimum required Runtime (in my case 4.5).
Is it possible?
Thanks!

So by runtime I am assuming you mean one of the assemblies in the NuGet package is compiled against .NET 4.5.
In NuGet Package Explorer create a directory:
lib\Net45
Then put the .NET 4.5 assembly or assemblies into that directory.
It looks like the NuGet Package Explorer supports creating a similar directory for Android.
lib\MonoAndroid
There is no version number here but all that means is the assembly should be considered compatible with any MonoAndroid version.

Related

Package nuget not installed correctly

I installed a package with Nuget on VisualStudio, but in the Packages of my project, this message appears in the extension I installed. What should I do to make it work properly?
The extension is: ThriveGmbH.BottomNavigationBar
Package 'ThriveGmbH.BottomNavigationBar.LATEST 1.0.6' was restored
using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2,
.NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1,
.NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of
the project target framework '.NETStandard,Version=v2.0'. This package
may not be fully compatible with your project.
Different projects can target different frameworks. Your project is targeting netstandard2.0, but the package you're depending on doesn't support any netstandard framework.
The only solutions are to not depend on that package, or to change the target framework of your project to net472 or one of the others in the list in the error message.

Package .NET framework DLL and use it in .NET standard project

I have a vendor provided DLL which is based on .NET Framework. I do not have access to code and I only have the DLL. I have packaged this DLL into a nuget package and now I am trying to refer this into a .NET standard project. But I am getting warning as - Package 'MyPackage 0.0.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project..
If I refer the DLL directly into a .NET standard project it doesn't show this warning. But using it after creating a nuget package shows that.
I also tried creating a .NET standard lib project, added DLL reference and then created a nuget package but still it was showing same warning.
Is there another way of doing it? Vendor doesn't provide DLLs targeting other frameworks and I have to use it after packaging it into Nuget because of requirements.
In my side, I test the situation as you described. Create a net standard lib project called test, then use this node to include into the package.
1) create a net standard lib nuget project called test and only add this node under test.csproj file:
<ItemGroup>
<None Include="xxx\xxx\xxx.dll"(the whole path of the net framework dll) Pack="true" PackagePath="lib\$(TargetFramework)"></None>
</ItemGroup>
2) right-click on the net standard test project-->click Pack button and you can get the new version of the nuget package.
Before you install the nuget package into another main project, you should first clean nuget caches or delete all files under C:\Users\xxx(current user)\.nuget\packages.
And I did not face the issue in my side with all the above steps.

Nuget-package not adding package reference

I am trying to install MySql.Data and MySql.Data.Entity to my class lib.
Somehow there is no reference added to the project.
Things I've tried:
Update-Package -reinstall (does not help)
packages.config contains the correct entries
*.csproj also has the correct entries
Cleared NuGet-Cache
This is the output:
Package 'MySql.Data.6.10.6' already exists in folder
'C:\Users\MYUSERNAME\Documents\Repositories\XXXXXXX\packages'
Added package 'MySql.Data.6.10.6' to 'packages.config'
Successfully installed 'MySql.Data 6.10.6' to XXXXXXXX.Persistence
Executing nuget actions took 1,6 sec
Strange thing is that NuGet creates that \docs in my project which is part of MySql
Nuget-package not adding package reference
I agree with Matt`s comment. You project targets framework should be .NET 4.5.1 or below. Because the package MySql.Data only contain assembly reference to .NET framework 4.5.2 for .NET framework:
However, this package also have the content files, which are compatible with .net framework. So when you add this package to the project(target framework 4.5.1 or below), nuget will install this nuget package without any error, just add the content file (\docs) but not add any reference to the project.
To resolve this issue, you can change the target framework to 4.5.2 and above of this project or you should use the nuget package MySql.Data with the version 6.9.11, which contain assembly reference to .NET framework 4.0 and 4.5:
Note: If you change the target framework to the .net framework 4.5.2 and above, you may get the error "The package 'MySql.Data' tried to add a framework reference to 'System.ComponentModel' which was not found in the GAC.", please add a manually reference to missed library:
Package tried to add reference to System.Runtime which was not found in the GAC
Hope this helps.
I experienced this problem even though I had the correct Framework.
It was solved by Migrating the Nuget Format to Package References
For visual studio latest versions you have to right click on Dependencies > Manage NuGet Packages > click in the settings button with a flower-like shape, then in NuGet Package Manager option choose General, and change Default package management format from packages.config to PackageReference.
If that does not do the trick, then you will have to add the packages through the CLI tools, looking into the nuget gallery and pasting the comand directly with the desired version, like for example:
dotnet add package Microsoft.EntityFrameworkCore.Design --version 6.0.10

Nuget System.Runtime.Numerics for .Net 4.0

I'm trying to target my project at .Net 4.0.
I have a dependency on System.Numerics.dll which is available in the .net 4.0.
My goal is to have my assembly work on a wide range of targets and be distributable via nuget (which I'm fairly new to).
So I started replacing my regular assembly references with nuget packages, so far so good. When I get to the nuget package System.Runtime.Numerics is has a dependency on .net 4.5. So I can't use it if I want to target .net 4.0.
Is this an issue with the packaging of System.Runtime.Numerics or am I missing something.
Is this an issue with the packaging of System.Runtime.Numerics or am I missing something.
Just as Hans Passant comment, "But specific to Numerics, the Nuget package has features that they considered too risky to include in framework 4.5.". You could get the framework support information from its referenced assembly:
So the package System.Runtime.Numerics does not contain any assembly references or content files that are compatible with .net 4.0 framework.
Update:
The nuget package starts support at .net 4.5 framework, so we don not recommend to get this package to target .net 4.0. If you are interesting in creating a nuget package that targets a wide range of targets including .net 4.0, I would like provide you with a simple method to try it:
Download the package System.Runtime.Numerics from nuget.org
Open it with NuGet Package Explorer.
Add a new folder named net40 and save it.
Then you add this package to the .net 4.0 framework project.

Adding MOQ to a .NET 4.0 project is not possible

I want to add MOQ .net library to a .NET 4.0 project. I get an error message that I should convert the project to something smaller than 4.0. I need to use .NET 4.0 also because of other project dependencies.
How can I make MOQ work with a .NET 4.0 project in VS2010 ?
Make sure you have NuGet package manager installed (Tools/Extension Manager).
Right click on Solution Explorer/References, choose Manage NuGet Packages.
Type Moq in the search box.
Install and enjoy.
The latest version from Google Code (http://code.google.com/p/moq/), works in a .Net 4.0 project. I would just download the dll again.
Here is the download link: http://code.google.com/p/moq/downloads/detail?name=Moq.4.0.10827.Final.zip
The zip file at that location contains a .Net 4 folder. Use the dll : Moq.dll from the NET40 folder and everthing will work fine. Just do a normal Add Reference on the project.
I would check the version number and the Runtime veseion of the assembly you are trying to use. It should say:
Runtime Version: v4.0.20926
Version: 4.0.10827.0
For the sake of completeness, it may be worth pointing out that it is also possible to use the Visual Studio command line package manager tool:
1) Open the console in VS
View >> Other Windows >> Package Manager Console
2) Install Moq
Type Install-Package Moq at the prompt
Note: If your tests are in a separate project, make sure that you select that project in the project dropdown.
This will install the latest package available in NuGet, which should address your compatibility issue. See http://nuget.org/packages/moq.
Watch out that you're using .NET 4, rather than the .NET 4 Client Profile as your Target Framework. I had the same issue and that was the cause for me.

Resources