Skip to content

Commit

Permalink
Refactor OperationTaskBase to derive from ToolTask
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd committed Mar 30, 2024
1 parent bfb5a6d commit 0710f43
Show file tree
Hide file tree
Showing 21 changed files with 244 additions and 148 deletions.
5 changes: 3 additions & 2 deletions src/EFCore.Design/Design/Internal/DbContextOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public virtual string ScriptDbContext(string? contextType)
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual IReadOnlyList<string> Optimize(string? outputDir, string? modelNamespace, string? contextTypeName)
public virtual IReadOnlyList<string> Optimize(string? outputDir, string? modelNamespace, string? contextTypeName, string? suffix)
{
using var context = CreateContext(contextTypeName);
var contextType = context.GetType();
Expand Down Expand Up @@ -149,7 +149,8 @@ public virtual IReadOnlyList<string> Optimize(string? outputDir, string? modelNa
ContextType = contextType,
ModelNamespace = finalModelNamespace,
Language = _language,
UseNullableReferenceTypes = _nullable
UseNullableReferenceTypes = _nullable,
Suffix = suffix
});

var fullName = contextType.ShortDisplayName() + "Model";
Expand Down
7 changes: 4 additions & 3 deletions src/EFCore.Design/Design/OperationExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,13 +531,14 @@ public OptimizeContext(
var outputDir = (string?)args["outputDir"];
var modelNamespace = (string?)args["modelNamespace"];
var contextType = (string?)args["contextType"];
var suffix = (string?)args["suffix"];

Execute(() => executor.OptimizeContextImpl(outputDir, modelNamespace, contextType));
Execute(() => executor.OptimizeContextImpl(outputDir, modelNamespace, contextType, suffix));
}
}

private IReadOnlyList<string> OptimizeContextImpl(string? outputDir, string? modelNamespace, string? contextType)
=> ContextOperations.Optimize(outputDir, modelNamespace, contextType);
private IReadOnlyList<string> OptimizeContextImpl(string? outputDir, string? modelNamespace, string? contextType, string? suffix)
=> ContextOperations.Optimize(outputDir, modelNamespace, contextType, suffix);

/// <summary>
/// Represents an operation to scaffold a <see cref="DbContext" /> and entity types for a database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ public class CompiledModelCodeGenerationOptions
/// </summary>
/// <value> A value indicating whether nullable reference types are enabled. </value>
public virtual bool UseNullableReferenceTypes { get; set; }

/// <summary>
/// Gets or sets the suffix to attach to the name of all the generated files.
/// </summary>
/// <value> The suffix to attach to the name of all the generated files. </value>
public virtual string? Suffix { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public virtual IReadOnlyList<string> ScaffoldModel(

var scaffoldedModel = codeGenerator.GenerateModel(model, options);

if (options.Suffix != null)
{
foreach (var file in scaffoldedModel)
{
file.Path = file.Path.Insert(file.Path.LastIndexOf('.'), options.Suffix);
}
}

CheckOutputFiles(scaffoldedModel, outputDir);

Directory.CreateDirectory(outputDir);
Expand Down
1 change: 1 addition & 0 deletions src/EFCore.Tasks/EFCore.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<ItemGroup>
<NuspecProperty Include="AssemblyName=$(AssemblyName)" />
<NuspecProperty Include="OutputPath=$(OutputPath)" />
<NuspecProperty Include="ArtifactsBinDir=$(ArtifactsBinDir)" />
<NuspecProperty Include="DefaultNetCoreTargetFramework=$(DefaultNetCoreTargetFramework)" />
<NuspecProperty Include="Configuration=$(Configuration)" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Tasks/EFCore.Tasks.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<metadata>
$CommonMetadataElements$
<dependencies>
<group targetFramework=".NET8.0">
<group targetFramework="$DefaultNetCoreTargetFramework$">
<dependency id="Microsoft.EntityFrameworkCore.Design" version="$Version$" />
</group>
</dependencies>
Expand All @@ -17,7 +17,7 @@
<file src="$OutputPath$$DefaultNetCoreTargetFramework$\$AssemblyName$.pdb" target="tasks\$DefaultNetCoreTargetFramework$\" />
<file src="$OutputPath$$DefaultNetCoreTargetFramework$\$AssemblyName$.deps.json" target="tasks\$DefaultNetCoreTargetFramework$\" />
<file src="$OutputPath$net472\*" target="tasks\net472\" />
<file src="..\..\artifacts\bin\ef\$Configuration$\netcoreapp2.0\*" target="tools\netcoreapp2.0\" />
<file src="$ArtifactsBinDir$ef\$Configuration$\netcoreapp2.0\*" target="tools\netcoreapp2.0\" />
<file src="buildTransitive\*" target="buildTransitive\" />
</files>
</package>
14 changes: 11 additions & 3 deletions src/EFCore.Tasks/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/EFCore.Tasks/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,15 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="NETCoreApp1StartupProject" xml:space="preserve">
<value>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</value>
<value>Startup project '{startupProject}' targets framework '.NETCoreApp' version '{targetFrameworkVersion}'. This version of the Entity Framework Core 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</value>
</data>
<data name="NETStandardStartupProject" xml:space="preserve">
<value>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</value>
<value>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 Tools with this project, add an executable project targeting .NET Core that references this project, and set it as the startup project using --startup-project; or, update this project to cross-target .NET Core. For more information on using the Entity Framework Tools with .NET Standard projects, see https://go.microsoft.com/fwlink/?linkid=2034781</value>
</data>
<data name="NotExecutableStartupProject" xml:space="preserve">
<value>Startup project '{startupProject}' cannot be executed directly. To use the Entity Framework Core Tools with this project, add an executable project targeting .NET Core that references this project, and set it as the startup project using --startup-project.</value>
</data>
<data name="UnsupportedFramework" xml:space="preserve">
<value>Startup project '{startupProject}' targets framework '{targetFramework}'. The Entity Framework Core .NET Command-line Tools don't support this framework. See https://aka.ms/efcore-docs-cli-tfms for more information.</value>
<value>Startup project '{startupProject}' targets framework '{targetFramework}'. The Entity Framework Core Tools don't support this framework. See https://aka.ms/efcore-docs-cli-tfms for more information.</value>
</data>
</root>
Loading

0 comments on commit 0710f43

Please sign in to comment.