pekspro / EF-Migrations-Script-Generator-Task

24 stars 7 forks source link

Could not execute because the specified command or file was not found. #23

Closed drfbwilliams closed 4 years ago

drfbwilliams commented 4 years ago

Hi,

I've been using the task for a while now without an issue. I just added it to a new pipeline and it is failing with the post title description.

The only difference is that I am attempting to generate from a .Net Core 3 Class Library file - which also happens to be the startup in the solution, because the solution is made up of library projects.

Finds the data context fine, but just cant get over the line. The project file is in the correct location confirmed by the build action.

I did read where you state to include a path to a project using a library as a startup? That doesn't quite make sense to me - are you saying that I need to add a new executable project to the solution, referencing the library, just to generate a script?

Thanks for any assistance here.

pekspro commented 4 years ago

Hi! Have your checked the setting Install dependencies for .NET Core 3?

You might be required to add an executable project to be able to generate a script, I am not sure if it is possible to do that with just libraries.

drfbwilliams commented 4 years ago

Hi - thanks for the response.

Yes, I have that checked and even specify the version of EF which works on another pipeline.

I am going to try and add a dummy project, which will be quite nasty if that is a requirement. Will update this on result.

Cheers

drfbwilliams commented 4 years ago

As an update - I can confirm EF is an entire mess.

For anyone else reading this coming to the same issue .....

Firstly, let me clear that it is NOT this Task that is causing the problem.

The issue revolves around the use of EF and how migration scripts are generated. There are a lot of issues when you step out from the normal use case of EF migrations in a primary .Net Core WEB application.

My initial setup was - data contexts in a seperate project, data models in another - both class libraries.

I slowly but sure had to keep modifying the data context project, adding this package, adding that package... eventually I had hand crafted a rather ugly Core Web app.

I also created a separate dummy core 3.1 web app that referenced the library and was marked as the startup application as well - no dice.

While it is entirely possible to run the EF command locally on my machine and successfully build the SQL scripts (even with the Frankenstein solution), there is no single configuration in Azure DevOps that will run the EF commands correctly.

This is the error that is present on every Agent type - the strange and unsolvable issue being a reference to 'Microsoft.NETCore.App' version '1.1.9' - This reference is nowhere in my solution/project(s) and even after specifically and explicitly importing a version on the list, this error still occurs.

image

So my only solution was to create a single .Net Core 3.1 Web Application as a single host of the data contexts.

I didn't want this because of the overhead - the context references are used by a lot of other projects.

If you are facing the same, try running this command from the package manager, which may help you dig deeper into issues as they arise. But make sure you grab a coffee, because this is going to hurt.

dotnet ef migrations script --project <full path>\<your-proj>.csproj --startup-project <full path>\<your-proj>.csproj --output <full path>\<your-proj>\outputmigrations\<your-db-contextname>.sql --context <your-db-contextname> --verbose --idempotent

An entirely wasted 6 hours.