dotnet / EntityFramework.Docs

Documentation for Entity Framework Core and Entity Framework 6
https://docs.microsoft.com/ef/
Creative Commons Attribution 4.0 International
1.63k stars 1.96k forks source link

How to pass MSBuild parameters when using the ef tools? #1261

Open metoule opened 5 years ago

metoule commented 5 years ago

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.

bricelam commented 5 years ago

Will this work?

dotnet build -p:MyParam=Whatever
dotnet ef --no-build ...
metoule commented 5 years ago

Yes, it works, thanks! That's even better, because now my continuous integration won't compile the code twice :)

rubberduck203 commented 3 years ago

I'm soooo happy this workaround exists, but it would be much better if ef could pass through any -p arguments to build.

rafalkwol commented 1 year ago

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 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.

AndreyPolovodov commented 4 months ago

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.

CordreSmith commented 4 days ago

Is there any movement on ef passing through -p arguments?

roji commented 3 days ago

This issue is in the Backlog milestone. This means that it is not planned for the next release (EF Core 8.0). We will re-assess the backlog following the this release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources. Make sure to vote (👍) for this issue if it is important to you.