Mostly I was using
this web site for my example.
In my case I have created the project C:\projects\ReverseGeoCoding, then open PowerShell, and first, if you don't have EF tool installed, execute following:
dotnet tool install --global dotnet-ef
Go to project folder, like cd "C:\projects\ReverseGeoCoding", and add packages "Microsoft.EntityFrameworkCore.Design" and "MySql.EntityFrameworkCore" like:
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package MySql.EntityFrameworkCore --version 5.0.0-m8.0.23
Now scaffold:
dotnet ef dbcontext scaffold "SERVER=localhost;DATABASE=myDb;UID=uid;PASSWORD=pass;" MySql.EntityFrameworkCore -o C:\projects\ReverseGeoCoding -f
Now, I have made my own console applicatcation for scaffolding:
using System.Diagnostics;
using System.Threading;
namespace MySQLScaffold
{
class Program
{
static void Main(string[] args)
{
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo
{
CreateNoWindow = false,
UseShellExecute = false,
FileName = "dotnet",
WindowStyle = ProcessWindowStyle.Hidden,
Arguments = "ef dbcontext scaffold"
+ " \"SERVER=localhost;DATABASE=myDb;UID=uid;PASSWORD=pass;\""
+ " MySql.EntityFrameworkCore -o"
+ " C:\\projects\\ReverseGeoCoding"
+ " -f -v"
+ " -p C:\\projects\\ReverseGeoCoding"
};
Mutex myMutex;
if (!Mutex.TryOpenExisting("testMutex", out myMutex))
{
myMutex = new Mutex(true, "testMutex");
myMutex.WaitOne();
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess?.WaitForExit();
}
}
catch
{
// Log error.
}
finally
{
myMutex.ReleaseMutex();
}
}
//Console.WriteLine("Press any key");
//Console.ReadKey();
}
}
}
Then I have created Class library application "EFCore", where in prebuild event I have added
C:\projects\MySQLScaffold\MySQLScaffold\bin\Debug\netcoreapp3.1\MySQLScaffold.exe
I had to add package "Microsoft.EntityFrameworkCore.Design", and I had to reference my "ReverseGeoCoding" project, here is how my "EFCore.csproj" look like:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="C:\projects\MySQLScaffold\MySQLScaffold\bin\Debug\netcoreapp3.1\MySQLScaffold.exe" />
</Target>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ReverseGeoCoding\ReverseGeoCoding.csproj" />
</ItemGroup>
</Project>