Closed AraHaan closed 2 years ago
cc: @ajcvickers this is a blocking issue for me.
I just tested this with updating the runtimes manually and it still does not work.
Edit: changed tfm to net 7 and still it fails with the exact same error, it seems the tool itself is broken somewhere.
This looks to be an issue where something might be referencing the System.Runtime.Experimental
package or w/e it's name is.
Ah It might be the references in Microsoft.Data.SqlClient
biting me (it's reference to System.IO which references an outdated System.Runtime
.
According to PerfView: the only thing asking for System.Runtime v6 on this is: System.CommandLine, otherwise the tool uses the .NET 7 copy.
@AraHaan can this be closed or do you still think there's an EF Core issue here?
Honestly I am not entirely sure if CommandLine is the root, as well I ran it with dotnet trace and it would not self exit the program without me pressing enter (to have dotnet trace terminate it) 10 minutes later. So it is possible that PerfView might have wrong data.
@AraHaan we'd need a minimal project which reproduces the problem in order to investigate this.
I will work on that as soon as I get back to my computer.
Alright got it done:
MyBot.Database.zip (I minimalized it to just the small db and sql code to run so the scaffolder can try to scaffold it)
As for the command it's:
dotnet ef dbcontext scaffold "Data Source=(local)\SQLEXPRESS;Initial Catalog=Bot;Integrated Security=True;Encrypt=True;TrustServerCertificate=True;User Instance=False" Microsoft.EntityFrameworkCore.SqlServer -t DiscordToken -t ExpiringVerifications -t Patrons -t Roles -t Tiers --use-database-names --data-annotations -c BotDbContext --context-dir Model -o Model -n MyBot.Database --no-onconfiguring -f -s "MyBot.Database.csproj" -p "MyBot.Database.csproj"
Ah, when I tested again with all the other runtimes, ref packs to them, and the Sdk's that are not 6.0.200/6.0.300-preview it results in this on the command I sent above:
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '2.0.0' (x64) was not found.
- The following frameworks were found:
6.0.3 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
When 2.0.9's runtime is installed, it results in the FileLoadException for 6.0.0's System.Runtime. It seems for some reason the tool wants to require 2.0.0, but then tries to roll forward to 6.0.0 and fail.
Ok, so I have tested and that https://github.com/dotnet/efcore/pull/27671 does infact fix this issue.
/cc @bricelam
Is this really your entire project file?
<Project Sdk="Microsoft.NET.Sdk" />
How are you referencing the EFCore packages? How are you running the commands?
This error is usually only seen in extreme corner cases where the .runtime.json file doesn't get generated on build.
@bricelam I reference the packages in Directory.Packages.props
, build settings in Directory.Build.props
, and <ItemGroup>
items in Directory.Build.targets
.
@AraHaan Is there some reason for going down this path instead of using the daily build?
I thought the dotnet-7 freed versions were the daily builds of dotnet-ef?
Also even with the daily build of the .NET runtime it was asking for the 6.0.0 version of System.Runtime before the roll forward patch on the tool called by dotnet-ef.
@AraHaan If the tooling doesn't work with the 6.0 runtime/SDK installed by the time we ship, then that would be problem. But its early days, so for now, just have 6.0 installed. EF Core 7.0 targets .NET 6.0 anyway, so there is no need to use it with 7.0.
I tried the preview 5 tool just now and still have this issue.
It seems that RollForward was not enough to fix the issue somehow.
https://github.com/dotnet/efcore/commit/06b2b1f75fbfd16501d2b6bfec6d0374cf203b03
Looks the only option now is to drop on the src/ef folder all TFM's that are not .NET 6 so that way the tool starts working again.
Yep changing the src/ef project from netcoreapp2.0 to net6.0 fixed the problem permanently.
Note: I did not drop the .NET Framework target at all to prevent possible breaking changes.
File a bug
When trying to scaffold my database using text templates, the resulting is an FileLoadException after build succeeds.
Include your code
The following is my project files (excluding code and sensitive information):
csproj:
Directory.Build.props:
Directory.Build.targets:
Directory.Packages.props:
nuget.config feeds:
Include stack traces
Include verbose output
Please include
--verbose
output when filing bugs about thedotnet ef
or Package Manager Console tools.Use triple-tick fences for tool output. For example:
Include provider and version information
EF Core version: Latest on dotnet-7 feed. Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 6 Operating system: Windows IDE: Visual Studio 2022 17.2 Preview 2