-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tools: Support .NET Core Class Library projects #5320
Comments
Hi, Just to be sure, we can't use EF within a class library project (aka tests project) in RC2? |
@Kurira you can use EF within a class library. You can't use EF .NET Core CLI commands on a class library. See https://docs.efproject.net/en/latest/cli/dotnet.html more info |
So I would use tools from my web project and apply them to test context which resides in test project? |
I need to test this more, but here is my solution that seems to be working: #5460 (comment) |
Is there a published workaround for this issue? I've added:
and a main() in program.cs, but I still get the "..Entity Framework tools does not support targeting class library projects.." message. |
@ToddThomson you are probably hitting https://github.com/dotnet/cli/issues/3164. Try setting the top-level emitEntryPoint build option to true. |
@natemcmaster Yes. That was it. |
When we have this implemented we need to verify that the right-click->Publish migrations feature works when the context/migrations is in a class library - I suspect it is not going to work by default because it will likely need to specify some of the target/startup project parameters. |
Additionally, if your DbContext takes a parameter then you also need to add a simple startup.cs to the class library. I added:
This was sufficient for me to add an initial migration for Identity services. |
@natemcmaster Any change in this regard in latest tooling preview 2? |
We are still blocked on .NET Core CLI support for this. https://github.com/dotnet/cli/issues/2645. Preview 2 added |
Hi, where can i use this "--startup-project" to fix that? |
@arielcloud did you upgrade your version of .NET Core CLI to preview 2? |
@natemcmaster i dont sure I have CLI at all. I downloaded .net core by "Visual Studio users: The best way to develop with .NET Core on Windows is using Visual Studio. You will need Visual Studio 2015 Update 3 and then download the .NET Core for Visual Studio official MSI Installer" where can i see if i have CLI and it's version? 10x! |
@arielcloud execute |
Yes, you can have your model or DbContext in a class library. This issue is about making the Migrations tooling experience a little better. Right now, you have to use an app (non-library) startup project for them to work at all. I'm working on changes that will largely remove this restriction, although maybe not always for |
@bricelam Which means we still have to reference EF Core to the web project ? |
So there's good news and bad news... The good news is that I got it "working". The bad news is that, in practice, it doesn't really "work" because the .NETStandard framework isn't intended for execution. It will work if everything down the execution path has a pure .NETStandard implementation that doesn't depend on a runtime. So basically the only command that will always work is:
None of the other commands will work on SQL Server because SqlClient is too framework-and-runtime-specific. You get:
SQLite is a little better because anything that doesn't actually open a connection will work:
Anything else will throw:
So, the question is, do we...
|
If we do allow execution, we should consider automatically add |
We'll go with the warning approach |
As a developer trying to use EFcore and having to deal with this issue because we are leveraging a common data model across multiple web portals and even a Xamarin project for Android - my team would prefer to have the option and the warning message. It feels a lot more natural to do data modeling and schema work against the Data project, not the application. |
@bricelam so you are saying there will be no issues with a .NET Core class library targeting only full .NET Framework instead of .NET Standard? |
Correct. Class libraries targeting .NET Framework or .NET Core App should work just fine without specifying a separate startup project. |
To ellaborate, there are two projects when you invoke a command: The target project that you are operating on. Files will be added to this project. The startup project. This is the runtime environment we'll emulate at design time. This project's config will be loaded; it's In PMC, the target project defaults to the selected Default project and can be overridden using On CLI, the target project defaults to the one in the working directory and can be overridden using |
For the first time I kind of understand this, how about adding this to the docs? |
@ErikEJ good idea. We don't really have any detailed docs on the commands at the moment, just a reference on what parameters are available etc. |
Good news |
Scratch that. It was an unrelated issue. .NET Standard class libraries will "work" (as much as they can) |
Can we add a way to persist the startup project in our class library so we don't need to pass the argument on every call and also we can share which startup project should be used in source control ? (Thinking in multiple project sharing (or not) the same dbcontext. maybe |
discard my last comment. I found a better way that I think it should be the official way because it's easy and afaik there's no downside. To make your class library be able to run Example:
this is also mentioned on the "workarounds" |
6 hours.... worked....
|
Add support for running "dotnet ef" on a .NET Standard and desktop .NET class library project.
This is blocked by https://github.com/dotnet/cli/issues/2645
and/or https://github.com/dotnet/cli/issues/4005 (depending on our implementation approach).Short explanation
If you cannot do
dotnet run
, you also cannot usedotnet ef
on your project.More explanation
.NET Core, unlike .NET Framework, does not have a globally installed framework. All .NET Core apps need to reference an app framework (e.g. Microsoft.NETCore.App) in order to run. .NET Core class library projects are built without a framework, so dotnet-ef cannot run on these projects.
Workarounds
See https://docs.efproject.net/en/latest/miscellaneous/cli/dotnet.html#targeting-class-library-projects-is-not-supported for workarounds.
The text was updated successfully, but these errors were encountered: