When I read about standard libraries i understand it as it can be used with core and standard (correct me if I am wrong). I have created a Standard library as a data library.
I now want to implement DocumentDB so I added the nuget package:
So my dependencies looks like this:
However I am not able to use the nuget package:
I dont get any errors, so I am guessing it must be the framework target? Any pointers here?
If you take a look at the dependencies on the Microsoft.Azure.DocumentDB package, it is dependent on .NET Framework v4.6.1. While .NET Standard 2.0 allows the loading of packages from .NET Framework it's discouraged as you can run into unexpected errors.
Instead you can use the Microsoft.Azure.DocumentDB.Core package or the new v3 package Microsoft.Azure.Cosmos as they both target .NET Standard directly so there will be no compatibility issues.
Related
I have a .NET Framework library with NuGet package dependencies. This library is consumed exclusively by .NET Framework projects. Some of them by local project references, and most through NuGet. I publish the library to a private NuGet server.
A few projects have cropped up using .NET Core based infrastructure, and I would like to make my standard library available to these projects. I am not switching any of the existing infrastructure to .NET Core. I don't want to introduce .NET Core dependencies into every existing .NET Framework project. I have noticed that when I install certain multi-targeted libraries, sometimes they include "netstandard" or something like that -- and install lots of dependencies. These are unacceptable and get immediately uninstalled from .NET Framework projects.
Is it possible to multi-target my .NET Framework (4.72 if it matters) project to .NET Core as well, while still producing native .NET Framework libraries? I can copy and paste all the code in my library into a netcoreapp3.1 project, install NuGet dependencies, and that code runs fine. However, I don't want to port this library to .NET Core, and then multi-target it back to .NET Framework. As far as I am aware, that is not the same as having a native implementation. I just want to be able to use the library in a .NET Core app without copying and pasting the entire library, and letting the versions get out of sync. The less ceremony the better.
My csproj file doesn't have a <TargetFramework or <TargetFrameworks> property. It has a <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> property.
Is what I'm trying to do possible? I can't tell from the documentation I have read.
I am trying to install nuget which was built using .NET Framework 4.7.1 into project which is on .netstandard 2.0. However, I am getting warning like
Package 'xyz' was restored using '.NETFramework,Version=v4.7.1' instead of the project target framework '.netstandard2.0'. This package may not be fully compatible with your project.
and nuget package is not getting installed correctly causing file missing exceptions when I run unit test cases. I can see 2 options resolving this issue :
I should change my original nuget package to support .NET Framework 4.7.1 as well .netstandard 2.0. Not sure if this is feasible? If yes please let me know the steps.
Changes my nuget consumer project to use both of these versions.
I have given couple of tries to figure out the way using above options but still not luck!
Thanks all for your response! I was able to figure out the solution by creating new .net standard project and migrating the .net framework code to it.
Good Reference to brush up the basics about these .NET offerings : https://code-maze.com/differences-between-net-framework-net-core-and-net-standard/
I have been trying to add the Square.Connect nuget package so that I can integrate with the square up payment system.
When I am trying to add the package I am getting an error:
"Could not install package 'Square.Connect 2.14.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', 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."
I have tried on a new application using .net 3.5 and .net 2.0 but I get the same error but with the changed target version.
Has anyone been able to get around this or can you advise me what I maybe doing wrong?
According to nuget.org https://www.nuget.org/packages/Square.Connect/ the Square.Connect package is for .NETStandard 2.0. So you should target that. Hint: Expand dependencies on the nuget page, to see what it requires.
This package is incompatible with your project.
You should target .NET Standard 2.0 or .NET Full Framework 4.6.1 or higher.
Both can work with .NET Standard 2.0 assemblies.
.NET Core 2.0 too, but that's not usefull for you, I guess!
As Palle Due's answer says, the package information page for the most recent version of the package lists .NET Standard 2.0 as a dependency. Therefore, your project must target something compatible with .NET Standard 2.0. This table lists several compatible runtimes, such as .NET Framework 2.6.1 or higher, .NET Core 2.0 or higher, as Schwarzie2478's answer listed (but he didn't give source information, which I think is useful). The table also lists minimum versions for some other runtimes like Xamarin's Android/iOS, or Unity game engine.
However, if you look at some older versions of the package, 2.10.1.297 and earlier depend on .NET Framework 4.5. Therefore, if for some reason you can't target a newer version of the .NET Framework, you could use these older versions of the package. Although I don't know any reason why anyone would be stuck on such an old version of the Framework. .NET Framework lifecycle is complex and very difficult to find a table with actual dates, but my guess is that no supported server operating system is limited to .NET Framework 4.5, so any server installing security updates will probably be on .NET Framework 4.6.x or more likely 4.7.x, so I really don't see any good reason to stay on net45.
I'm having a .Net 4.7.2 application, in which I want to reference the package OpcFoundation.NetStandard.Opc.Ua. This project as a list of dependencies for .Net 4.6 that is quite small.
But when I install it, I get like 50+ additional packages to install. Is there a way to reduce this? I feel that a lot of thoses classes are already existing in the full .Net project(System.Threading.Tasks/Timer/...).
Thank you
If you look at many of these types (which are supplied by .NET Standard packages, not .NET Core), you'll find that the specific version that's used against .NET 4.7.2 will be an empty assembly just containing lots of TypeForwardedTo attributes pointing right back at the full-flavour .NET Framework.
So you still end up using the exact types you always would have done. There's just extra indirections which allows .NET Standard to work with both .NET Framework, .NET Core and other .NET Standard implementations.
I have a Xamarin Forms project and the majority of times that I want to install a nuget package I have an error saying that:
Install-Package : Could not install package 'Microcharts 0.7.1-pre'. You are trying to install this package into a project that targets
'.NETPortable,Version=v4.5,Profile=Profile259', but the package does not contain any assembly references or content files that are compatible with that framework.
I Assume I can work this out by changing the project .net framework target. But when I go and change it, I get an error saying that it cannot change the target because that implies upgrading nuget to 3.0 and It canĀ“t do that.
So my question is: Which is the best way(and simplest) to change the target framework so I have less problems like above with nuget packages.
This library was built to target .NETStandard v1.4. You are trying to use it in a PCL project, that is not possible. PCL is on the way out as the previous not-so-good way to build cross-platform libraries, .NETStandard is the new way.
There is no older version available of this library, rebuilding it from source is a possible option. But realistically it is time to move on to avoid hitting this wall over and over again, you need to update your tooling so you can consume these kind of libraries. The VS2017 Community edition is freeware.
It is time to go from your
.NET PCL Library to an appropriate .NET Standard Library.
Here are some links concerning the migration to .NET Standard.
Upgrade PCL to .NET Standard Class Library
.NET Standard 2.0 Support in Xamarin.Forms
Converting PCL (Portable Class Libraries) to .NET Standard Class Libraries
.NET Standard - PCL Compatibility
.NET Standard Implementation Support
My Suggestion concerning the version of the .NET Standard to use.
If you don't care about backwards compatibility (You want to use the latest OS and SDKs) go all the way to .NET Standard 2.
If you want to have a good backward compatibility you should go on .NET Standard 1.1 - 1.5.
On most projects i use 1.4 - 1.5.