Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/EFCore.Tasks/PACKAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ This package should be referenced by the project containing the derived `DbConte

## Usage

Install the package into your project, set `<EFOptimizeContext Condition="'$(Configuration)'=='Release'">true</EFOptimizeContext>` and then run build normally.

If the startup project is different from the current project it needs to be specified: `<EFStartupProject>..\Startup\Startup.csproj</EFStartupProject>`
Install the package into your project and then run build normally. For solutions where specifying the startup project is necessary, set `<EFStartupProject>..\Startup\Startup.csproj</EFStartupProject>`

The startup project must also reference the `Microsoft.EntityFrameworkCore.Tasks` package.

You can control when code generation occurs by setting `<EFScaffoldModelStage>build</EFScaffoldModelStage>` or `<EFPrecompileQueriesStage>build</EFPrecompileQueriesStage>` to generate during build instead of the default publish stage.

## Getting started with EF Core

See [Getting started with EF Core](https://learn.microsoft.com/ef/core/get-started/overview/install) for more information about EF NuGet packages, including which to install when getting started.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<!-- Usage:
For the compiled model and precompiled queries to be generated when publishing with $(PublishAOT) set to true the only action needed is to reference Microsoft.EntityFrameworkCore.Tasks from all projects containing a derived DbContext or a query.
For solutions where specifying the startup project is necessary, IDesignTimeDbContextFactory<> should be implemented.
$(EFOptimizeContext) can be set to true to enable code generation outside of NativeAOT.
$(EFScaffoldModelStage) and $(EFPrecompileQueriesStage) can be set to either publish or build to control at what stage will the code be generated. Any other value will disable the corresponding generation (in case the code is generated manually using `dotnet ef dbcontext optimize`)
If there's more than one context and $(DbContextType) is not set, then the compiled model will be generated for all of them.
$(EFTargetNamespace) and $(EFOutputDir) can be used to further fine-tune the generation.
Expand All @@ -39,12 +38,12 @@ $(EFTargetNamespace) and $(EFOutputDir) can be used to further fine-tune the gen

For Publish:

1. If PublishAOT is true _EFPrepareDependenciesForPublishAOT in the startup project invokes _EFGenerateFilesBeforePublish on all dependencies even if they don't set EFOptimizeContext to true. Otherwise _EFGenerateFilesBeforePublish runs on the projects before Publish.
1. If PublishAOT is true _EFPrepareDependenciesForPublishAOT in the startup project invokes _EFGenerateFilesBeforePublish on all dependencies. Otherwise _EFGenerateFilesBeforePublish runs on the projects before Publish.
2. _EFGenerateFilesBeforePublish calls _EFGenerateFiles and the rest is similar to the Build flow.
-->

<Target Name="_EFGenerateFilesAfterBuild"
Condition="'$(_EFGenerationStage)'=='' And '$(EFOptimizeContext)'=='true' And ('$(EFScaffoldModelStage)'=='build' Or '$(EFPrecompileQueriesStage)'=='build')">
Condition="'$(_EFGenerationStage)'=='' And ('$(EFScaffoldModelStage)'=='build' Or '$(EFPrecompileQueriesStage)'=='build')">
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="_EFGenerateFiles"
BuildInParallel="$(BuildInParallel)"
Expand All @@ -55,7 +54,7 @@ For Publish:
<Target Name="_EFGenerateFilesBeforePublish"
AfterTargets="GetCopyToPublishDirectoryItems"
BeforeTargets="GeneratePublishDependencyFile"
Condition="'$(_EFGenerationStage)'=='' And ('$(EFScaffoldModelStage)'=='publish' Or '$(EFPrecompileQueriesStage)'=='publish') And ('$(EFOptimizeContext)'=='true' Or ('$(EFOptimizeContext)'=='' And ('$(_EFPublishAOT)'=='true' Or '$(PublishAOT)'=='true')))">
Condition="'$(_EFGenerationStage)'=='' And ('$(EFScaffoldModelStage)'=='publish' Or '$(EFPrecompileQueriesStage)'=='publish')">>
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="_EFGenerateFiles"
BuildInParallel="$(BuildInParallel)"
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet-ef/RootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected override int Execute(string[] _)
&& _args[0] == "dbcontext"
&& _args[1] == "optimize"
&& !_args.Any(a => a == "--no-scaffold");
startupProject.Build(skipOptimization ? new[] { "/p:EFOptimizeContext=false" } : null);
startupProject.Build(skipOptimization ? new[] { "/p:EFScaffoldModelStage=none", "/p:EFPrecompileQueriesStage=none" } : null);
Reporter.WriteInformation(Resources.BuildSucceeded);
}

Expand Down