There are TONS of posts, blogs, articles, etc... explaining all of this confusing stuff with regard to .Net/.NetCore/.NetStandard and I have read many of them.
Here is the issue, I have a Windows 10 UWP app and I need to reference a library that I created. I first created the library as a NetCore library but I could not reference that from my UWP app (which is confusing because UWP uses .Net Core but the .Net Core library I created assumed this was for ASP.NET?).
So, then I tried to create the library as a PCL library and targeted ONLY Windows 10 UWP (which it then forces you to Windows 8.1 because they are the same). With this type of library I am confident I would be able to reference it from my UWP app but it caused me to lose too many .Net namespaces that I could not get the library to build.
Finally, I then selected the link, in the project properties, to target the .Net Standard instead. I selected .Net Standard 1.4 and suddenly, I had all the namespaces I needed available to me and I was able to build my library. I am also able to successfully add it as a reference to my UWP app.
However, I am getting the following 6 exceptions and they don't tell me too much about the root cause so I can fix it.
So, my main question is, can you reference a .Net Standard 1.4 library in your UWP app? Second, any ideas what these exceptions mean?
Thanks!
EDIT - I have uploaded both csproj files here:csproj files
Okay, I found that answer but it was based mainly on this answer which I did not see before posting my question due to search terms (I have literally spent over a day searching and trying to find an answer).
Answer that helped:
Here is a summary:
.NetStandard 1.4 is supported by UWP.
By default, VS 2015 Update 3 template for a UWP project imports Microsoft.NetCore.UniversalWindowsPlatform version 5.1.0. I am sure the VS 2017 template will start off with a newer version, 5.1.0 is fairly old. So, based on the answer linked above, I updated (using NuGet) to the newest version allowed by VS 2015 Update 3 which at the time of this answer, is version 5.2.3. There is a 5.3.x version but it requires VS 2017.
Finally, I modified the project.json in my UWP project to import the netstandard1.4 framework. It looks like this:
"frameworks": {
"uap10.0": {
"imports": "netstandard1.4"
}
And, with those simple steps, I can get the UWP project to build and those 6 errors above go away.
Hope this helps!
Related
I am developing an app with .NET Standard 2.0 project as core project, so bumped into the fact, that I am not sure how I should (can) handle the famous easy-to-access-and-setup approach with MvvmCross.
Search for Cirrious.MvvmCross.Plugins.Sqlite plugin in Nuget doesn't return anything (apparently it's been a while and it's not supported).
SQLite-PCL doesn't seem like sound .NET Standard-ish, plus there is a whole bunch of different packages with similar name (and with no any close reference to MvvmCross actually) appear.
There is also a reference to sqlite-pcl-net plugin in release notes for MvvmCross 5, but it also "doesn't smell" Mvx-y.
So, what's going on with MvvmCross SQLite these days? What should I use? Any ideas?
There used to be an official MvvmCross Plugin for SQLite but it was dropped sometime around early 2017 because the plugin was redundant. SQLite is probably the most popular database used in MvvmCross applications, but there is nothing in MvvmCross requiring this. You are still free to use Realm, Entity Framework Core, etc.
You should be using the praeclarum/sqlite-net version of SQLite since Android 7.0. Here is the NuGet feed for the package. This version supports .NET Standard and PCL. Other forks are not maintained as much, or stopped working reliably on Android due to the changes to the way SQLite was changed in Android 7.0.
I've also recently provided another answer to a question asking how to add SQLite to an MvvmCross application since the plugin was removed. I provided some sample code for Android in the answer. The old MvvmCross SQLite Plugin source code is also still available.
I'm currently using a PCL in my Xamarin.Forms project and would like to change it to a .NET Standard library. I've looked up tutorials and as far as I understand the first step is to click the "Target .NET Platform Standard" option in the PCL project's properties. The issue is this option is not shown to me, instead, to me, there's a text saying "Learn More" which when clicked takes me to a page comparing .NET Standard to PCL and more https://learn.microsoft.com/en-us/dotnet/standard/net-standard#comparison-to-portable-class-libraries. What should I do?
I did run into the same problem. We tried to convert all our PCLs to .NET Standard. And we thought, that let them "Target .NET Standard" makes them pure .NET Standard libs, but this assumption was wrong. We ran into several problems, untill we realized, that there are some small differences between a PCL Targeting .NET Standard and a pure .NET Standard library.
The Solution was to create new libraries for every PCL and copy the files into the .NET Standard libraries. We are working on .NET Standard 2.0 libs in our Xamarin project now and everything works as expected. Atleast after we updated our VisualStudio to the newest version and after updating resharper to an EAP Release.
So i'd recommend you to go the same way and just create new .NET Standard libraries for your PCL projects and copy the contents.
Additional Information
Microsoft.NetCore.CompatibilityPack
You will run into issues of incopatibility with nuget Packages that do not support .NET Standard yet. You will need this package
Channel9 How To
The following links provides a Channel9 video showing how to migrate to .NET Standard. The guy also talks about the CompatibilityPack and fallback targets https://channel9.msdn.com/Shows/XamarinShow/Snack-Pack-15-Upgrading-to-XamarinForms-to-NET-Standard
I'm using Visual Studio Code on Mac OS X to develop .NET Core web APIs. I already understand that adding NuGet references is done manually in the project.json file.
However, I'm not quite sure how to search NuGet for .NET Core specific libraries. The Mac OS X tutorial in the .NET Core documentation only instructs the developer to add project dependencies, and it doesn't go into detail about how the developer would know / discover the dependency names.
Is there a way to search NuGet specifically for .NET Core libraries, and/or libraries that are compatible with .NET Standard? I would like to use the Mac OS X terminal or even VSCode to do this. However, any solution would be a great starting point.
ps. I did come across Reverse Package Search, but I have no idea who created it, how up-to-date it is, and if it will be available six months from now.
Right now (as of January 2017), there's no easy way to search unfortunately. It's an open issue on the NuGet Github project.
The closest you can get right now is to look at the package dependencies after you find it (see my answer here). That doesn't help you find it in the first place, though. It's currently a manual "educated guess" process.
I've recently had to some work in Unity that required classes only available in the later versions of .NET, which Unity does not yet support. I managed to download the very few scripts that I was missing and added it to my project and it seems to work fine. What I wanted to know is why can I not just take the entire .NET source and shove it into my projects? What are the implications of doing something like that?
EDIT: The scripts that I have added so far was the generic version of WeakReference as well as any dependencies that it needed (Contract in System.Diagnostics.Contract).
EDIT EDIT: I basically want to know why I can't simply just the C# class files found in the later versions of .NET to Unity, which uses an older version of .NET. Is it a software issue? Is it a hardware issue? Is it because Unity's system components were built in correspondence with the earlier version of .NET?
SHORT ANSWER:
Install the Visual Studio Tools for Unity (it should automatically get installed when you install Unity), when you do you can tell your .csproj in the "target framework" drop-down to target the special version of .NET Unity uses and you will only be able to compile dll's that have methods and types that Unity supports.
LONG ANSWER:
It is because Unity does not use the installed version of .NET on your computer. Unity uses Mono, and a very old version at that. This allows unity to be ran on multiple platforms and OSes. Because of that you can only use features that are in the supported version of Mono.
However, if you look at their roadmap the alpha build you will see
Scripting: C# Compiler Upgrade
Upgrade Mono C# compiler against our
current .Net 2.0 and 2.0 Subset profiles. Note that this is an upgrade
of the C# compiler only, not the full Mono runtime
Then further on in the "research" phase
Scripting: .NET Profile Upgrade
Upgrade .Net profile to 4.6 enabling access to the latest .Net functionality and APIs.
UPDATE:
You can get a experimental build that uses the 4.6 profile from the stickied post here.
Here are the notes for the 5.6.0b5 beta release
For this release, the Editor and the following players should be working:
Windows, OSX, Linux standalone
iOS with IL2CPP
Android with IL2CPP and Mono
Other platforms are known to not work yet, and are probably not worth installing.
Managed debugging via Visual Studio Tools for Unity or MonoDevelop is not supported in this release. If you want to use VSTU for
editing please use the special build linked at the bottom of this
post.
The compiler targets the C# 6 language.
The compiler by default will still target the .Net 4.6 framework profile.
Known issues
The Android/Mono build does not work properly with managed code stripping. Please disable managed code stripping for now.
For some projects, the Windows standalone player can crash on Windows 8.1. This is intermittent, so we would love to see any crash
reports or data about this
A similar question was answered before here. Like I described in your other question, you can "inject" newer stuff and use them, but sooner or later they'll backfire (e.g. can't compile to particular systems, can compile but cannot be published in whatever mobile store, surprisingly slow execution, huge builds, etc. Worst case your project will be compromised).
If you really cannot refactor the project you are working on and you feel you must use 'up-to-date technology', bear in mind the injected classes code must be data objects, means, not at all related to GameObjects.It is also adviced to derive from ScriptableObject when and where possible.EDIT: But I'd recommend what I told you earlier (refactor) or what the linked answer describes ('export' the code incompatible with mono/.net2.0 to an external dll and use it from there)
I am creating a fresh Mono for android application using http://xamarin.com/monoforandroid
I selected Mono for Android Application using Visual C# option.
My Android target version is :
I went to references of the project and tried adding my pre existing dlls (made in .NET 4 Framework)
and I got this error:
The strange stuff is there is no option to change the .NET Framework from project properties. Can you tell me what I am missing?
The problem here is that you're trying to reference a .NET 4 DLL from a project that isn't .NET 4. Mono for Android uses its own profile for .NET, which is very similar to that of Silverlight (but not exactly the same). While it's possible that adding a DLL compiled for a different profile will work, it's very risky as you will probably run into problems at runtime where your app will crash, due to something being missing from the Mono for Android profile.
The best answer right now is to create a Mono for Android class library, link in the appropriate files from the library you want to use, and reference that. This will give you compile-time checking that you're not using anything unsupported by the Mono for Android profile, and help keep you more sane in the long run. I have an old blog post up here that talks about how to link files across projects.
That said, in this case you're in luck because someone else has already done that last part for you! Check out this fork of Json.NET which provides versions for MonoTouch and Mono for Android.
The strange stuff is there is no option to change the .NET Framework from project properties. Can you tell me what I am missing?
It's not particularly strange - that dialog box was written by Microsoft, with its own project types in mind. It sounds like Mono for Android doesn't have the same options available.
I strongly suspect you'll just have to use a version of JSON.NET targeting .NET 3.5.
(Having said that, Mono for Android claims to support "dynamic language features" which sounds like it should be targeting .NET 4. Odd. I suspect the fix is the same though.)