@@ -146,6 +146,8 @@ protected override int Execute(string[] _)
146146 Resources . PlatformSpecificProject ( startupProject . ProjectName , startupProject . TargetFramework ) ) ;
147147 }
148148
149+ var additionalProbingPaths = new List < string > ( ) ;
150+
149151 var targetFramework = new FrameworkName ( startupProject . TargetFrameworkMoniker ! ) ;
150152 if ( targetFramework . Identifier == ".NETFramework" )
151153 {
@@ -171,21 +173,24 @@ protected override int Execute(string[] _)
171173 using var file = File . OpenRead ( projectAssetsFile ) ;
172174 using var reader = JsonDocument . Parse ( file ) ;
173175 var projectAssets = reader . RootElement ;
174- var packageFolders = projectAssets . GetProperty ( "packageFolders" ) . EnumerateObject ( ) . Select ( p => p . Name ) ;
176+ var packageFolders = projectAssets . GetProperty ( "packageFolders" )
177+ . EnumerateObject ( ) . Select ( p => Path . TrimEndingDirectorySeparator ( p . Name ) ) . ToList ( ) ;
175178
176179 foreach ( var packageFolder in packageFolders )
177180 {
178181 args . Add ( "--additionalprobingpath" ) ;
179- args . Add ( packageFolder . TrimEnd ( Path . DirectorySeparatorChar ) ) ;
182+ args . Add ( packageFolder ) ;
180183 }
184+
185+ additionalProbingPaths = packageFolders ;
181186 }
182187
183188 if ( File . Exists ( runtimeConfig ) )
184189 {
185190 args . Add ( "--runtimeconfig" ) ;
186191 args . Add ( runtimeConfig ) ;
187192 }
188- else if ( startupProject . RuntimeFrameworkVersion ! . Length != 0 )
193+ else if ( ! string . IsNullOrEmpty ( startupProject . RuntimeFrameworkVersion ) )
189194 {
190195 args . Add ( "--fx-version" ) ;
191196 args . Add ( startupProject . RuntimeFrameworkVersion ) ;
@@ -258,6 +263,13 @@ protected override int Execute(string[] _)
258263 args . Add ( "--prefix-output" ) ;
259264 }
260265
266+ // Only `migrations bundle` understands these (it launches a child ef.dll for DbContext discovery);
267+ // every other ef.dll command rejects unrecognized options.
268+ if ( IsMigrationsBundle ( commands ) )
269+ {
270+ args . AddRange ( GetBundleHostArgs ( depsFile , runtimeConfig , startupProject . RuntimeFrameworkVersion , additionalProbingPaths ) ) ;
271+ }
272+
261273 if ( _applicationArgs ! . Any ( ) )
262274 {
263275 args . Add ( "--" ) ;
@@ -267,6 +279,49 @@ protected override int Execute(string[] _)
267279 return Exe . Run ( executable , args , startupProject . ProjectDir ) ;
268280 }
269281
282+ internal static bool IsMigrationsBundle ( IReadOnlyList < string > commands )
283+ => commands . Count >= 2
284+ && string . Equals ( commands [ 0 ] , "migrations" , StringComparison . OrdinalIgnoreCase )
285+ && string . Equals ( commands [ 1 ] , "bundle" , StringComparison . OrdinalIgnoreCase ) ;
286+
287+ // The startup project's host context, forwarded so `migrations bundle` can launch its out-of-process
288+ // discovery child the same way this tool launched ef.dll. See https://github.com/dotnet/efcore/issues/25555.
289+ internal static IReadOnlyList < string > GetBundleHostArgs (
290+ string depsFile ,
291+ string runtimeConfig ,
292+ string ? runtimeFrameworkVersion ,
293+ IReadOnlyList < string > additionalProbingPaths )
294+ {
295+ var args = new List < string > ( ) ;
296+
297+ if ( File . Exists ( depsFile ) )
298+ {
299+ args . Add ( "--deps-file" ) ;
300+ args . Add ( depsFile ) ;
301+ }
302+
303+ if ( File . Exists ( runtimeConfig ) )
304+ {
305+ args . Add ( "--runtime-config" ) ;
306+ args . Add ( runtimeConfig ) ;
307+ }
308+ else if ( ! string . IsNullOrEmpty ( runtimeFrameworkVersion ) )
309+ {
310+ // Mirrors the host --fx-version so the child can pin the same shared framework when there is
311+ // no runtimeconfig.json.
312+ args . Add ( "--runtime-framework-version" ) ;
313+ args . Add ( runtimeFrameworkVersion ) ;
314+ }
315+
316+ foreach ( var additionalProbingPath in additionalProbingPaths )
317+ {
318+ args . Add ( "--additional-probing-path" ) ;
319+ args . Add ( additionalProbingPath ) ;
320+ }
321+
322+ return args ;
323+ }
324+
270325 private static ( string , string ) ResolveProjects (
271326 string ? projectPath ,
272327 string ? startupProjectPath )
0 commit comments