Issue with applying EF Core migrations at design time #9554
Replies: 2 comments 4 replies
-
Why are you adding to the migrations to the app host project? They are supposed to be added to an application that references the dbcontext. |
Beta Was this translation helpful? Give feedback.
-
Myself, and a couple of other devs I code with on hobby projects outside of work have also hit this issue. A good explanation of the situation and the practical issues its causing for folks trying to adopt aspire for the first time is covered in this blog post. I understand that MS have been focused on build recently and will now be working towards the .net 10 Q4 release but IMHO this situation, for those following the recommended docs from MS on seeding DBs prevents the use of the recommended approach from the EF Core docs This might be a great opportunity for some cross team collaboration that would leave those of us trying to learn how to adopt the best approaches to EF in an aspire world in a bit better position. To be clear I am not certain this needs a code change to either EF or Aspire, although it could be solved with an overload or better detection of the fact migration is underway. Rather if there is a recommended approach that would work around this then adding that to the already otherwise very thorough (and much improved in the last year) aspire docs would present a for more pleasant first experience for those starting out with aspire, for many of whom the connection of an app to a database and running a migration will be some of their first use cases. Thanks for all the hard work on Aspire. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is there an existing issue for this?
Describe the bug
On non-aspire projects, I am used to creating and applying EF Core migrations using add-migration and update-database command in VS PMC. I am trying to do the same thing in the Aspire project, where even though the distributed app is not running, I am hoping that the database can be started just long enough to apply the migrations. I followed this article: https://khalidabuhakmeh.com/add-ef-core-migrations-to-dotnet-aspire-solutions
I added a DesignTimeDbContextFactory to my app host project and added a project reference to my project containing the dbcontext.
My add-migration command succeeded, but the 'update-database` command throws this error: "Property CliPath: The path to the DCP executable used for Aspire orchestration is required.; Property DashboardPath: The path to the Aspire Dashboard binaries is missing."
My DesignTimeDbContextFactory is noted below. Note that I am on .Net Aspire 9.3 version.
Expected Behavior
No response
Steps To Reproduce
Add the DataContextDesignTimeFactory to the App Host, and add a project reference to the project containing dbcontext. In PMC, select the default project as the project containing dbcontext.
In PMC. issue commands
add-migration test
, and thenupdate-database
Exceptions (if any)
Property CliPath: The path to the DCP executable used for Aspire orchestration is required.; Property DashboardPath: The path to the Aspire Dashboard binaries is missing.
...........................................................
Unable to create a 'DbContext' of type 'RuntimeType'. The exception 'Database did not become available within 3 minutes. Make sure Docker is running.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
.NET Version info
.NET SDK:
Version: 9.0.300
Commit: 15606fe0a8
Workload version: 9.0.300-manifests.af4147de
MSBuild version: 17.14.5+edd3bbf37
Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.300\
.NET workloads installed:
[wasm-tools]
Installation Source: VS 17.14.36121.58
Manifest Version: 9.0.5/9.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.workload.mono.toolchain.current\9.0.5\WorkloadManifest.json
Install Type: Msi
Configured to use loose manifests when installing new manifests.
Host:
Version: 9.0.5
Architecture: x64
Commit: e36e4d1a8f
.NET SDKs installed:
9.0.300 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Anything else?
Beta Was this translation helpful? Give feedback.
All reactions