How to pass MSBuild parameters when using the ef tools?
When you run the dotnet ef tools, they first call the dotnet msbuild tool. My projects require certain parameters to run properly; when I manually call dotnet build, I can pass them via the -p parameter, for example:
dotnet build -p:MyParam=Whatever.
How can I pass MSBuild parameters when calling dotnet ef?
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 263f21d6-6edc-7582-e0e2-fa1c9670bcc0
- Version Independent ID: b3dd8c84-18b1-f98d-64f1-7897d1482692
- Content: EF Core tools reference (.NET CLI) - EF Core
- Content Source: entity-framework/core/miscellaneous/cli/dotnet.md
- Product: entity-framework
- GitHub Login: @bricelam
- Microsoft Alias: bricelam
Will this work?
dotnet build -p:MyParam=Whatever
dotnet ef --no-build ...
Yes, it works, thanks! That's even better, because now my continuous integration won't compile the code twice :)
I'm soooo happy this workaround exists, but it would be much better if ef could pass through any -p arguments to build.
I tried to use this workaround for "dotnet ef migrations bundle" command, but it seems that after doing the build the "dotnet ef migrations bundle --no-build" command is not working due to the "cannot access file...being used by another process" that is being discussed in #25555.
I'm trying to inject into the compilation a custom method with ModuleInitializerAttribute without modifying the original files or directories in any way. The build works well if I pass a custom "CustomBeforeMicrosoftCommonProps" property (I can see the method when I decompile the assembly). However the bundling part is affected with the mentioned issue and cannot be completed. I'm not passing the property to "dotnet ef migrations bundle" because it's not possible at the moment (according to my knowledge). The publish process seem to only have a lock issue with the main assembly which is the project passed as --project and --startup-project (both of those have the same value and the project is a .NET 8 class library containing DbContext derived class and IDesignTimeDbContextFactory<T> implementation). All the other dependencies are published fine according to the log.
Any idea how I could pass the property to the publish part of "dotnet ef migrations bundle" command? As it would allow me to get rid of the separate build step and --no-build flag which combined seem to cause the issue. Before any questions why I'm doing all this - I need to inject a module initializer to make some environment variables part of the package so there is no need to pass them on another server when starting the bundle. :)
I'm hoping someone will be able to help with this issue.
I can't use workaround with --no-build, because I need to pass /p:PlatformName, but with --no-build dotnet ef migrations uses default platform "Any CPU" which doesn't work in my solution. But I've found the solution finally, use:
$env:Platform = "x64" before dotnet ef commands.