So i try to develop little andriod application by Xamarin Studio 5.4. I have three projects in my solution - project of android application (ClientProject), some class library that used by first one (MyLib) and some console application (ConsoleApp).
But when i try to add reference to MyLib into ClientProject i fail. Xamarin Studio tells me that "Incompatible target framework .NET Framework Version 4.0".
That looks this
I changed MyLib's framework version to 3.5, to 4.5 but it takes no effect.
But when i try to add this reference into ConsoleApp there is no problem:
So i have to add to ClientProject a reference to MyLib.dll so I can not debug its code.
What should i do to solve this problem?
The Android project will have a framework of MonoAndroid. This framework is incompatible with the full .NET Framework. Your options are to do one of the following:
Create an Android Library Project.
Create a Portable Class Library Project.
Create a Shared Project.
If you are only interested in creating an Android application, and not interested in using the library for other mobile platforms, then the first option will be the simplest.
Related
Startup project 'EFGetStartedUWP' is a Universal Windows Platform app. This version of the Entity Framework Core Package Manager Console Tools doesn't support this type of project. For more information on using the EF Core Tools with UWP projects, see https://go.microsoft.com/fwlink/?linkid=858496
I'm trying to connect SQLite Database to a basic UWP app for the sake of learning but when I try migration. It just keep giving me the above error. I've searched quite a lot on the internet but didn't get the appropriate answer. The Microsoft documentation is of no use in this scenario. Also I've installed Microsoft.EntityFrameworkCore.Sqlite & Microsoft.EntityFrameworkCore.Tools.
If anyone can suggest any other way to connect SQLite database to UWP that'll be very useful too as I'm quite new to C# and I've a university project to do on a UWP app.
I've just stepped on a similar issue, and I've been lucky enough to solve it. To start with, I found these links very useful:
Entity Framework Core tools reference - .NET Core CLI - Other target frameworks and Common options.
In my case, my solution ended up with a configuration like this:
the application project (Universal Windows) - startup project for the solution,
a class library project (.NET Standard 2.0) - with the models and context classes,
a dummy console app project (.NET 6.0) - necessary to act like a startup project for the tools.
Have into account that (at the time of writing) UWP doesn't support .NET Standard 2.1. It supports .NET Standard 2.0 from version 10.0.16299. This means the (Universal Windows) application project can't reference a .NET Standard 2.1 project (e.g. .NET 5.0, .NET Core 3.0, Mono 6.4, etc.), so the class library project CAN'T be .NET 2.1, .NET 5.0, etc. The opposite is not true: a .NET 5.0 or .NET 6.0 project can reference a .NET Standard 2.0 project, so the dummy console app project can be .NET 6.0.
Steps to add a migration:
In the class library project, install the Nuget package for the corresponding EFCore platform used (e.g. for SQLite, install Microsoft.EntityFrameworkCore.Sqlite). Do not install the most recent version but the last that depends on .NET Standard 2.0, which is 3.1.21 at the time of writing.
In the dummy console app project, install this Nuget package: Microsoft.EntityFrameworkCore.Design. For compatibility purposes, install the same version as the version chosen in the previous step (e.g. 3.1.21).
In the application project, add a reference to the class library project. (Right-click on the project, select Add > Project Reference..., and tick the class library project.)
In the dummy console app project, add a reference to the class library project. Note there's no need to change anything else in the dummy console app project, although the project doesn't have to be built (less deployed), so feel free to open the Configuration Manager, and untick Build (and Deploy). In addition, in the Configuration Manager, don't bother to change the platform (x64, Any CPU...) to be the same as the referenced class library project. After all, the dummy console app project won't be built, so ignore any warnings about the architecture not being the same as the class library project.
Rebuild your solution to make sure there are no other issues going on. If there are any, fix them before continuing.
Open the command prompt (tip: navigate to the root folder of your solution with Windows File Explorer and type cmd in the address bar to open the command prompt in that folder).
Type the following (-p signals the target project while -s indicates the startup project):
?> dotnet ef migrations add #MigrationName -s #DummyConsoleAppProject -p #ClassLibraryProject
Optionally, unload the dummy console app project, and load it again next time you need it to add a migration.
This looks to be a known issue from here: https://github.com/aspnet/EntityFrameworkCore/issues/9666
Using EFCore with UWP is a bit finicky.
So, add a new project to your solution -> select .net core console app -> create DBContext and your models there -> run the "Add-Migration" command and reference it back to your main project.
That should get rid of that error and let you use migrations with UWP.
I am using Visual Studio 2017. I have a solution and in that solution I have 2 projects. One project is a library I made. This library is using Target Framework .Net Standard 1.6 and Output type: Class Library. The other project is a Windows Application using Target Framework: .Net Framework 4.6.1 and output type: Windows Application.
I added my class library to my windows application and the reference is in the Reference section, but when I try to use a class from the library, it cannot find it. Also I tried adding the "Using MyLibrary" and it still cannot find the reference. What else can I do?
I'm not sure why but the whole solution must had been corrupted or something. So I remade a whole new solution and created the projects again and copied all my files over and it worked. Not sure what the whole problem was but it is now working.
I am currently working on a UWP app (which automatically has reference to Microsoft.NETCore.UniversalWindowsPlatform when I added it). Now I want to reference a class library (contains the models for code reuse) running under .Net Framework 4.5.x into the UWP app but when I try to add the dll it throws this error
" could not be added. The project targets '.NETCore' while file
reference targets '.NETFramework'. This is not a supported scenario."
Is there any work around for this?
Any answers/tips are highly appreciated!
Because as the error says UWP doesn't support .Net libraries.
Possible solution is to extract and port needed code so you can use it in .Net and UWP projects.
There are several options: .Net Standart or Portable class library
I am new to Windows Metro app and I'm recently involved in building an app that sends mails with attachments. When I try to add a reference to the project, an error is displayed:
The project targets .NET Core while the file reference targets .NET Framework.
Is there any way to remove this error?
A Metro style app must use references to another .NETCore or Portable Library binary only...
It can not reference a full .NET library because the Metro profile is not that large (and would fail store certification).
You will have to create a portable version of the library you want.
I think you have created a normal Windows Application type project. For this Application type you have to reference DLLs from .NetFramework folder instead of .NETCore folder.
In Visual Studio 2012 in a blank new Class Library I am trying to add reference to an existing project in the solution, also a Class Library, MonoGame.Framework.Windows8 (https://github.com/mono/MonoGame), but get the error:
Unable to add reference to Project MonoGame.Framework.Windows8
I have built the existing library, MonoGame, successfully and made it a dependency of the new one. What could be the problem?
(It's extremely annoying the error message does not give a reason!)
Trying to add the built dll has a reference gave a more explicit error message which has solved the problem for me, it said:
“A reference to ‘x’ could not be added. The project targets ‘.NetFramework’ while the file reference targets ‘.NetCore’. This is not a supported scenario”
The MonoGame Class Library is a Class Library (Windows Store apps) type! (The bit in parenthesis is important! Presumably the difference is the Windows Store apps type use .Net Core which is not the same as .Net Framework).
So to get it working your project must be a Class Library (Windows Store apps) which is available under the Windows Store option in Add New Project.
I suspect the problem is to do with the 'Target Framework' in project options.
I don't know how MonoGame works for Windows 8 but when you're developing for Android the target framework options are the different versions of Android [e.g. Android 2.2 (Froyo)]. When you create a regular class library you have choices between the different versions of the .NET framework or Mono [e.g. Mono / .NET 4.0].
Unfortunately, these frameworks are not compatible with each other. You can't add a project reference for Android to a .NET framework class library and visa-versa.
The solution is to use a Portable Class Library. They are specifically designed to deal with this issue. The downside is that you will only have access to the subset of assemblies provided in the lowest denominator you choose to target.
You might also want to consider code sharing between projects using linked files. It can make maintenance a little trickier but gives you a little more control over code that should compile in both target frameworks but doesn't fit into the portable class library. Here's a related question:
Project reference vs. file links in Mono multi-target projects
The key to all of this once you understand what's going on here is how you structure your solution. With a little care you can have nearly all your code shared across different platforms.
I might be because of both projects are using different Framework versions and change the Framework versions in both Projects of properties section then your problem might solve.
Same question I guess here:
Visual Studio 11 metro apps unable to add reference?
The answer was:
What are you adding a reference to? Metro style apps can only add references to other Metro style class libraries or portable class libraries