ErikEJ / EFCorePowerTools

Entity Framework Core Power Tools - reverse engineering, migrations and model visualization in Visual Studio & CLI
MIT License
2.16k stars 297 forks source link

EFPT: Improve .NET Core process launcher #50

Closed ErikEJ closed 5 years ago

ErikEJ commented 6 years ago

C:\Code\EntityFramework\src\dotnet-ef\RootCommand.cs

bricelam commented 6 years ago

This code is more appropriate if you have access to EnvDTE: https://github.com/aspnet/EntityFrameworkCore/blob/dev/src/EFCore.Tools/tools/EntityFrameworkCore.psm1#L757-L872

ErikEJ commented 6 years ago

I do not, but thanks

ErikEJ commented 5 years ago

@bricelam I actually do have access to EnvDTE, thanks for the hint!

ErikEJ commented 5 years ago

@bricelam Does this mean I MUST intall EFCore.Design 2.2.4 in order to make this work? (It works if I do)

dotnet exec --depsfile "C:\Users\Erik\Downloads\ConsoleApp3\ConsoleApp3\bin\Debug\netcoreapp2.2\ConsoleApp3.deps.json" --additionalprobingpath "C:\Users\Erik\.nuget\packages" --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig "C:\Users\Erik\Downloads\ConsoleApp3\ConsoleApp3\bin\Debug\netcoreapp2.2\ConsoleApp3.runtimeconfig.json" "C:\Users\Erik\AppData\Local\Temp\efpt\efpt.dll"  "C:\Users\Erik\Downloads\ConsoleApp3\ConsoleApp3\bin\Debug\netcoreapp2.2\ConsoleApp3.dll"
Error:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=2.2.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.EntityFrameworkCore.Design, Version=2.2.4.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
   at ReverseEngineer20.EfCoreModelBuilder.BuildResult(String outputPath, Boolean generateDdl)
   at ReverseEngineer20.Program.Main(String[] args) in C:\Code\EFCorePowerTools\src\GUI\efpt\Program.cs:line 44
bricelam commented 5 years ago

All dependencies of efpt.dll must be installed in the app. I think you can relax assembly version requirements by hooking AppDomain.CurrentDomain.AssemblyResolve:

AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
    var fullName = new AssemblyName(args.Name);

    // Ignore Version, Culture, and PublicKeyToken
    return Assembly.Load(fullName.Name);
}
ErikEJ commented 5 years ago

Thanks, just now I refer to version 2.1.0 and 2.2.0 of EfCore.Design, and it seems to work fine.

ErikEJ commented 5 years ago

Does AppDomain exist in .NET Core??

bricelam commented 5 years ago

Parts of it were added to 2.0. You can't create new ones though, so there is only ever one app domain per process.

bricelam commented 5 years ago

As an alternative they've added custom load contexts and enabled unloading assemblies.