diff --git a/src/EFCore.Tasks/EFCore.Tasks.csproj b/src/EFCore.Tasks/EFCore.Tasks.csproj index 2f8ab7f674d..8d91c9a30b7 100644 --- a/src/EFCore.Tasks/EFCore.Tasks.csproj +++ b/src/EFCore.Tasks/EFCore.Tasks.csproj @@ -39,7 +39,6 @@ - @@ -56,7 +55,6 @@ - diff --git a/src/EFCore.Tasks/lib/net10.0/_._ b/src/EFCore.Tasks/lib/net10.0/_._ deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/EFCore.Tools/EFCore.Tools.csproj b/src/EFCore.Tools/EFCore.Tools.csproj index 9d4949fc81f..caa33c35568 100644 --- a/src/EFCore.Tools/EFCore.Tools.csproj +++ b/src/EFCore.Tools/EFCore.Tools.csproj @@ -26,10 +26,7 @@ Update-Database - - - + @@ -51,12 +48,8 @@ Update-Database - - - - diff --git a/src/EFCore.Tools/lib/net8.0/_._ b/src/EFCore.Tools/lib/net8.0/_._ deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 b/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 index 994e18f553d..09ec3ae237e 100644 --- a/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 +++ b/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 @@ -1286,24 +1286,8 @@ function EF($project, $startupProject, $params, $applicationArgs, [switch] $skip if ($targetFramework -in '.NETFramework') { - $platformTarget = GetPlatformTarget $startupProject - if ($platformTarget -eq 'x86') - { - $exePath = Join-Path $PSScriptRoot 'net472\win-x86\ef.exe' - } - elseif ($platformTarget -eq 'ARM64') - { - $exePath = Join-Path $PSScriptRoot 'net472\win-arm64\ef.exe' - } - elseif ($platformTarget -in 'AnyCPU', 'x64') - { - $exePath = Join-Path $PSScriptRoot 'net472\any\ef.exe' - } - else - { - throw "Startup project '$($startupProject.ProjectName)' has an active platform of '$platformTarget'. Select " + - 'a different platform and try again.' - } + throw "Startup project '$($startupProject.ProjectName)' targets framework '.NETFramework'. The Entity Framework Core Package " + + 'Manager Console Tools don''t support .NET Framework projects. Consider updating the project to target .NET.' } elseif ($targetFramework -eq '.NETCoreApp') { @@ -1322,6 +1306,7 @@ function EF($project, $startupProject, $params, $applicationArgs, [switch] $skip $projectAssetsFile = GetCpsProperty $startupProject 'ProjectAssetsFile' $runtimeConfig = Join-Path $targetDir ($startupTargetName + '.runtimeconfig.json') $runtimeFrameworkVersion = GetCpsProperty $startupProject 'RuntimeFrameworkVersion' + # TODO: Remove TFM from the path, issue #37473 $efPath = Join-Path $PSScriptRoot 'net10.0\any\ef.dll' $dotnetParams = 'exec', '--depsfile', $depsFile diff --git a/src/dotnet-ef/Properties/Resources.Designer.cs b/src/dotnet-ef/Properties/Resources.Designer.cs index 87e0b1c1357..c722ed44878 100644 --- a/src/dotnet-ef/Properties/Resources.Designer.cs +++ b/src/dotnet-ef/Properties/Resources.Designer.cs @@ -362,7 +362,7 @@ public static string NativeAotWarning => GetString("NativeAotWarning"); /// - /// Startup project '{startupProject}' targets framework '.NETCoreApp' version '{targetFrameworkVersion}'. This version of the Entity Framework Core .NET Command-line Tools only supports version 2.0 or higher. For information on using older versions of the tools, see https://go.microsoft.com/fwlink/?linkid=871254 + /// Startup project '{startupProject}' targets framework '.NETCoreApp' version '{targetFrameworkVersion}'. This version of the Entity Framework Core .NET Command-line Tools only supports version 10.0 or higher. /// public static string NETCoreApp1StartupProject(object? startupProject, object? targetFrameworkVersion) => string.Format( @@ -370,7 +370,15 @@ public static string NETCoreApp1StartupProject(object? startupProject, object? t startupProject, targetFrameworkVersion); /// - /// Startup project '{startupProject}' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the Entity Framework Core .NET Command-line Tools with this project, add an executable project targeting .NET Core or .NET Framework that references this project, and set it as the startup project using --startup-project; or, update this project to cross-target .NET Core or .NET Framework. For more information on using the Entity Framework Tools with .NET Standard projects, see https://go.microsoft.com/fwlink/?linkid=2034781 + /// Startup project '{startupProject}' targets framework '.NETFramework'. The Entity Framework Core .NET Command-line Tools don't support .NET Framework projects. Consider updating the project to target .NET. + /// + public static string NETFrameworkStartupProject(object? startupProject) + => string.Format( + GetString("NETFrameworkStartupProject", nameof(startupProject)), + startupProject); + + /// + /// Startup project '{startupProject}' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the Entity Framework Core .NET Command-line Tools with this project, add an executable project targeting .NET Core references this project, and set it as the startup project using --startup-project; or, update this project to cross-target .NET Core or .NET Framework. For more information on using the Entity Framework Tools with .NET Standard projects, see https://go.microsoft.com/fwlink/?linkid=2034781 /// public static string NETStandardStartupProject(object? startupProject) => string.Format( diff --git a/src/dotnet-ef/Properties/Resources.resx b/src/dotnet-ef/Properties/Resources.resx index 14c8ae07f4e..323919ca847 100644 --- a/src/dotnet-ef/Properties/Resources.resx +++ b/src/dotnet-ef/Properties/Resources.resx @@ -286,10 +286,13 @@ NativeAOT support is experimental and can change in the future. - Startup project '{startupProject}' targets framework '.NETCoreApp' version '{targetFrameworkVersion}'. This version of the Entity Framework Core .NET Command-line Tools only supports version 2.0 or higher. For information on using older versions of the tools, see https://go.microsoft.com/fwlink/?linkid=871254 + Startup project '{startupProject}' targets framework '.NETCoreApp' version '{targetFrameworkVersion}'. This version of the Entity Framework Core .NET Command-line Tools only supports version 10.0 or higher. + + + Startup project '{startupProject}' targets framework '.NETFramework'. The Entity Framework Core .NET Command-line Tools don't support .NET Framework projects. Consider updating the project to target .NET. - Startup project '{startupProject}' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the Entity Framework Core .NET Command-line Tools with this project, add an executable project targeting .NET Core or .NET Framework that references this project, and set it as the startup project using --startup-project; or, update this project to cross-target .NET Core or .NET Framework. For more information on using the Entity Framework Tools with .NET Standard projects, see https://go.microsoft.com/fwlink/?linkid=2034781 + Startup project '{startupProject}' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot be executed directly. To use the Entity Framework Core .NET Command-line Tools with this project, add an executable project targeting .NET Core or .NET Framework that references this project, and set it as the startup project using --startup-project; or update this project to cross-target .NET Core or .NET Framework. For more information on using the Entity Framework Tools with .NET Standard projects, see https://go.microsoft.com/fwlink/?linkid=2034781 Don't build the project. Intended to be used when the build is up-to-date. diff --git a/src/dotnet-ef/RootCommand.cs b/src/dotnet-ef/RootCommand.cs index d019cf8c068..4fc038d25da 100644 --- a/src/dotnet-ef/RootCommand.cs +++ b/src/dotnet-ef/RootCommand.cs @@ -109,38 +109,17 @@ protected override int Execute(string[] _) var targetFramework = new FrameworkName(startupProject.TargetFrameworkMoniker!); if (targetFramework.Identifier == ".NETFramework") { - executable = Path.Combine( - toolsPath, - "net472", - startupProject.PlatformTarget == "x86" - ? "win-x86" - : "any", - "ef.exe"); + throw new CommandException( + Resources.NETFrameworkStartupProject(startupProject.ProjectName)); } else if (targetFramework.Identifier == ".NETCoreApp") { - if (targetFramework.Version < new Version(2, 0)) + if (targetFramework.Version < new Version(5, 0)) { throw new CommandException( Resources.NETCoreApp1StartupProject(startupProject.ProjectName, targetFramework.Version)); } - var targetPlatformIdentifier = startupProject.TargetPlatformIdentifier!; - if (targetPlatformIdentifier.Length != 0 - && !string.Equals(targetPlatformIdentifier, "Windows", StringComparison.OrdinalIgnoreCase)) - { - executable = Path.Combine( - toolsPath, - "net472", - startupProject.PlatformTarget switch - { - "x86" => "win-x86", - "ARM64" => "win-arm64", - _ => "any" - }, - "ef.exe"); - } - executable = "dotnet"; args.Add("exec"); args.Add("--depsfile"); @@ -174,6 +153,7 @@ protected override int Execute(string[] _) #if !NET10_0 #error Target framework needs to be updated here, as well as in Microsoft.EntityFrameworkCore.Tasks.props and EntityFrameworkCore.psm1 #endif + // TODO: Remove TFM from the path, issue #37473 args.Add(Path.Combine(toolsPath, "net10.0", "any", "ef.dll")); } else if (targetFramework.Identifier == ".NETStandard") diff --git a/src/dotnet-ef/dotnet-ef.csproj b/src/dotnet-ef/dotnet-ef.csproj index 9e103d02378..9ca666878d1 100644 --- a/src/dotnet-ef/dotnet-ef.csproj +++ b/src/dotnet-ef/dotnet-ef.csproj @@ -69,14 +69,12 @@ + - - - diff --git a/src/ef/AppDomainOperationExecutor.cs b/src/ef/AppDomainOperationExecutor.cs deleted file mode 100644 index 1b6506a75d8..00000000000 --- a/src/ef/AppDomainOperationExecutor.cs +++ /dev/null @@ -1,145 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#if !NET -using System.Collections; -using System.Reflection; -using Microsoft.EntityFrameworkCore.Design; -using Microsoft.EntityFrameworkCore.Design.Internal; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Tools.Properties; - -namespace Microsoft.EntityFrameworkCore.Tools -{ - internal class AppDomainOperationExecutor : OperationExecutorBase - { - private readonly object _executor; - private readonly AppDomain _domain; - private bool _disposed; - private string? _efcoreVersion; - private const string ReportHandlerTypeName = "Microsoft.EntityFrameworkCore.Design.OperationReportHandler"; - - public AppDomainOperationExecutor( - string assembly, - string? startupAssembly, - string? designAssembly, - string? project, - string? projectDir, - string? dataDirectory, - string? rootNamespace, - string? language, - bool nullable, - string[] remainingArguments, - IOperationReportHandler reportHandler) - : base( - assembly, startupAssembly, designAssembly, project, projectDir, rootNamespace, language, nullable, remainingArguments, - reportHandler) - { - var info = new AppDomainSetup { ApplicationBase = AppBasePath }; - - var reporter = new OperationReporter(reportHandler); - var configurationFile = (startupAssembly ?? assembly) + ".config"; - if (File.Exists(configurationFile)) - { - reporter.WriteVerbose(Resources.UsingConfigurationFile(configurationFile)); - info.ConfigurationFile = configurationFile; - } - - _domain = AppDomain.CreateDomain("EntityFrameworkCore.DesignDomain", null, info); - - if (dataDirectory != null) - { - reporter.WriteVerbose(Resources.UsingDataDir(dataDirectory)); - _domain.SetData("DataDirectory", dataDirectory); - } - - var designReportHandler = _domain.CreateInstanceAndUnwrap( - DesignAssemblyName, - ReportHandlerTypeName, - false, - BindingFlags.Default, - null, - [ - (Action)reportHandler.OnError, - (Action)reportHandler.OnWarning, - (Action)reportHandler.OnInformation, - (Action)reportHandler.OnVerbose - ], - null, - null); - - if (DesignAssemblyPath != null) - { - _domain.AssemblyResolve += (sender, args) => - { - var assemblyPath = Path.Combine(Path.GetDirectoryName(DesignAssemblyPath)!, args.Name + ".dll"); - return File.Exists(assemblyPath) ? Assembly.LoadFrom(assemblyPath) : null; - }; - } - - _executor = _domain.CreateInstanceAndUnwrap( - DesignAssemblyName, - ExecutorTypeName, - false, - BindingFlags.Default, - null, - [ - designReportHandler, - new Hashtable - { - { "targetName", AssemblyFileName }, - { "startupTargetName", StartupAssemblyFileName }, - { "project", Project }, - { "projectDir", ProjectDirectory }, - { "rootNamespace", RootNamespace }, - { "language", Language }, - { "nullable", Nullable }, - { "toolsVersion", ProductInfo.GetVersion() }, - { "remainingArguments", RemainingArguments } - } - ], - null, - null); - } - - public override string? EFCoreVersion - { - get - { - if (_efcoreVersion != null) - { - return _efcoreVersion; - } - - var designAssembly = _domain.GetAssemblies().Single(assembly => assembly.GetName().Name == DesignAssemblyName); - _efcoreVersion = designAssembly.GetCustomAttribute() - ?.InformationalVersion; - return _efcoreVersion; - } - } - - protected override object CreateResultHandler() - => new OperationResultHandler(); - - protected override void Execute(string operationName, object resultHandler, IDictionary arguments) - => _domain.CreateInstance( - DesignAssemblyName, - ExecutorTypeName + "+" + operationName, - false, - BindingFlags.Default, - null, - [_executor, resultHandler, arguments], - null, - null); - - public override void Dispose() - { - if (!_disposed) - { - _disposed = true; - AppDomain.Unload(_domain); - } - } - } -} -#endif diff --git a/src/ef/Commands/MigrationsBundleCommand.cs b/src/ef/Commands/MigrationsBundleCommand.cs index 0626b709aeb..c668bdec9d6 100644 --- a/src/ef/Commands/MigrationsBundleCommand.cs +++ b/src/ef/Commands/MigrationsBundleCommand.cs @@ -29,10 +29,6 @@ protected override void Validate() } } -#if !NET - protected override int Execute(string[] args) - => throw new CommandException(Resources.VersionRequired("6.0.0")); -#else protected override int Execute(string[] args) { string? version; @@ -78,7 +74,6 @@ protected override int Execute(string[] args) }; programGenerator.Initialize(); - // TODO: We may not always have access to TEMP var tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(tempDirectory); try @@ -174,8 +169,6 @@ protected override int Execute(string[] args) publishArgs.Add(configuration!); } - publishArgs.Add("--disable-build-servers"); - var exitCode = Exe.Run("dotnet", publishArgs, directory, handleOutput: Reporter.WriteVerbose); if (exitCode != 0) { @@ -218,5 +211,4 @@ protected override int Execute(string[] args) return base.Execute(args); } -#endif } diff --git a/src/ef/Commands/ProjectCommandBase.cs b/src/ef/Commands/ProjectCommandBase.cs index 0c926a488ba..f5423ce3456 100644 --- a/src/ef/Commands/ProjectCommandBase.cs +++ b/src/ef/Commands/ProjectCommandBase.cs @@ -1,9 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#if NET -using System.Runtime.Loader; -#else +#if !NET using System.Configuration; #endif using System.Reflection; @@ -80,47 +78,7 @@ protected IOperationExecutor CreateExecutor(string[] remainingArguments) Reporter.WriteWarning, Reporter.WriteInformation, Reporter.WriteVerbose); -#if !NET - try - { - return new AppDomainOperationExecutor( - Assembly!.Value()!, - StartupAssembly!.Value(), - _designAssembly!.Value(), - Project!.Value(), - _projectDir!.Value(), - _dataDir!.Value(), - _rootNamespace!.Value(), - _language!.Value(), - _nullable!.HasValue(), - remainingArguments, - reportHandler); - } - catch (MissingMethodException) // NB: Thrown with EF Core 3.1 - { - var configurationFile = (StartupAssembly!.Value() ?? Assembly!.Value()!) + ".config"; - if (File.Exists(configurationFile)) - { - AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configurationFile); - try - { - typeof(ConfigurationManager) - .GetField("s_initState", BindingFlags.Static | BindingFlags.NonPublic) - .SetValue(null, 0); - typeof(ConfigurationManager) - .GetField("s_configSystem", BindingFlags.Static | BindingFlags.NonPublic) - .SetValue(null, null); - typeof(ConfigurationManager).Assembly - .GetType("System.Configuration.ClientConfigPaths") - .GetField("s_current", BindingFlags.Static | BindingFlags.NonPublic) - .SetValue(null, null); - } - catch - { - } - } - } -#endif + return new ReflectionOperationExecutor( Assembly!.Value()!, StartupAssembly!.Value(), diff --git a/src/ef/ef.csproj b/src/ef/ef.csproj index 2ba92b8c779..4c3d18cda35 100644 --- a/src/ef/ef.csproj +++ b/src/ef/ef.csproj @@ -1,7 +1,8 @@  - $(NetMinimum);net472 + + $(NetMinimum);$(NetFrameworkToolCurrent) Entity Framework Core Command-line Tools Exe false @@ -25,7 +26,7 @@ - + @@ -67,9 +68,4 @@ - - - - - diff --git a/src/stubs/EFCore.Design.csproj b/src/stubs/EFCore.Design.csproj deleted file mode 100644 index 0d45e0f0ee8..00000000000 --- a/src/stubs/EFCore.Design.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - $(MSBuildProjectName)$([System.IO.Path]::DirectorySeparatorChar)stub - - - - - - net10.0 - Microsoft.EntityFrameworkCore.Design - true - $(NoWarn);NU5128 - false - - - - - \ No newline at end of file