-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dotnet ef migrations fail when using custom output paths and separate project/startup-projects #23853
Comments
/cc @bricelam |
Looks like you have that pesky sample code I tried to get rid of in dotnet/dotnet-docker#1033... |
Hmm, yep. The tools currently assume both projects have the same |
As part of #18840, we should explore ways we can improve this experience. Probably worth adding some docker-specific guidance in the docs too. |
As a quick fix, it would be good to pass efcore/src/dotnet-ef/RootCommand.cs Line 75 in 901bfb4
as done directly below efcore/src/dotnet-ef/RootCommand.cs Lines 76 to 81 in 901bfb4
This would pick up on "dynamic" |
We have this problem in our project. We have a separate project for our EF and API. We want to use a different build folder for linux and windows to allow us to build using wsl on the same folder as windows. We added this to our Directory.Build.Props:
But since I think we should be allowed to use relative paths for |
Was this postponed because the effort required did not justify the implementation, or the implementation was too complicated, or because the priority was too low? I ask because this affects almost all projects I do with EF Core. My typical use case is: I split my code into several csprojs:
I regularly choose this approach because I think it has some advantages (if you think this choice is sub-par, let me know):
I also redirect my bin/ and obj/ folders to be at the root of the repo, similar to what @AArnott does in Library.Template. I think this has these advantages:
Because of this issue, the
Obviously I was hoping for option 4 ;-). If you think what I'm doing is somehow weird or wrong or could be done better, please let me know. I would have thought this was a typical scenario for projects beyond very simple ones, but maybe I'm wrong when I look at the votes for this issue. If you think that would be an option, I could try to create a PR for this, but you can probably better tell whether that makes sense to try. |
Hey @bricelam, I hate to just come in with a "bump", as a maintainer on a large OSS project myself I get that is not ideal... That said, is there a status update of some kind on this issue? Aside from my work on Nx itself, I am the lead maintainer for the .NET plugin for it, and we redirect outputs into a folder that isn't within the project root as a standard. We do so to better fit Nx's conventions, and while its optional I'd like to continue to do that... Nx has remote caching, and distributed task execution. These features combined lets you build a parent project (say your webapi), and kick off child projects building (class libraries, etc) on any number of machines. As dependant builds finish, and parent builds start, the build intermediates and results are downloaded onto the machine that will be running the parent build. For large projects this is much, much faster. If the intermediates folder is within the project root, specifying the cache locations and task inputs for build targets is a bit more complex than I'd like. Is there anything I may be able to contribute which could further push this? My main reason for coming in with the bump is that we have the "punted-for7.0" tag, and 7.0 has released. For reference, this is what our users end up running into: nx-dotnet/nx-dotnet#673 |
I wrote an article with a workaround for Nx. https://dev.to/simplifycomplexity/using-entityframework-in-a-nxdotnet-environment-cfb Though the problem lies with EF core not respecting the build config xml file. I'll update the article to reference this issue. |
@bricelam Any chance this issue will be addressed soon? |
I hope to look at it in the 8.0 timeframe. |
I think I have a better temporary workaround for an Nx workspace. I have not tested yet for side-effects, but here is my solution. @AgentEnder you may be interested. I simply renamed me Then I conditionally excluded my entity-framework-core library in a fresh And I used a custom command called |
@bricelam 8.0 being released now, any updates? |
@sharky98 This issue is in the Backlog milestone. This means that it is not planned for the next release. 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. |
I run into this issue regularly. I also redirect my /bin and /obj via
Until this is fixed, is there any known way/workaround to use |
Please consider adding this to the v9.0 milestone; this has been a problem for years. Any workarounds in the meantime? |
read the issue, workaround is to use the |
@vchirikov It's incredibly ironic to tell other people to "read the issue" and simultaneously demonstrate not having done so yourself — that workaround does not work if you have separate startup and migration projects: see literally the original post here and also here, as well as this other comment. |
.gitignore:
Directory.Build.targets: <Project>
<!-- To use dotnet ef without 'msbuildprojectextensionspath' -->
<Import Condition="Exists('$(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).EntityFrameworkCore.targets')" Project="$(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).EntityFrameworkCore.targets" />
</Project> and use |
I have a DbContext.csproj that defines my I've set environment variables When I invoke
Checking the binlog for the build for DbContext.csproj, I can see that it succeeded and artifacts\obj\DbContext\DbContext.csproj.EntityFrameworkCore.targets file is there with the However, for Startup.csproj, there is no artifacts\obj\Startup\Startup.csproj.EntityFrameworkCore.targets file and, thus, no Because the file is not there, there is no file to import. I've created a local EntityFrameworkCore.targets with this: <?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="GetEFProjectMetadata">
<MSBuild Condition=" '$(TargetFramework)' == '' "
Projects="$(MSBuildProjectFile)"
Targets="GetEFProjectMetadata"
Properties="TargetFramework=$(TargetFrameworks.Split(';')[0]);EFProjectMetadataFile=$(EFProjectMetadataFile)" />
<ItemGroup Condition=" '$(TargetFramework)' != '' ">
<EFProjectMetadata Include="AssemblyName: $(AssemblyName)" />
<EFProjectMetadata Include="Language: $(Language)" />
<EFProjectMetadata Include="OutputPath: $(OutputPath)" />
<EFProjectMetadata Include="Platform: $(Platform)" />
<EFProjectMetadata Include="PlatformTarget: $(PlatformTarget)" />
<EFProjectMetadata Include="ProjectAssetsFile: $(ProjectAssetsFile)" />
<EFProjectMetadata Include="ProjectDir: $(ProjectDir)" />
<EFProjectMetadata Include="RootNamespace: $(RootNamespace)" />
<EFProjectMetadata Include="RuntimeFrameworkVersion: $(RuntimeFrameworkVersion)" />
<EFProjectMetadata Include="TargetFileName: $(TargetFileName)" />
<EFProjectMetadata Include="TargetFrameworkMoniker: $(TargetFrameworkMoniker)" />
<EFProjectMetadata Include="Nullable: $(Nullable)" />
<EFProjectMetadata Include="TargetFramework: $(TargetFramework)" />
<EFProjectMetadata Include="TargetPlatformIdentifier: $(TargetPlatformIdentifier)" />
</ItemGroup>
<WriteLinesToFile Condition=" '$(TargetFramework)' != '' "
File="$(EFProjectMetadataFile)"
Lines="@(EFProjectMetadata)" />
</Target>
</Project> and imported it in Startup.csproj with: <!-- To use dotnet ef without 'msbuildprojectextensionspath' -->
<Import Condition="!Exists('$(BaseIntermediateOutputPath)\obj\$(MSBuildProjectFile).EntityFrameworkCore.targets')" Project="EntityFrameworkCore.targets" /> The strange part is that is that Startup.csproj.EntityFrameworkCore.targets exists in artifacts\obj\DbContext. @ajcvickers, @roji, I think I have the correct solution for this. Just give me a few days. |
- Refactor MSBuild integration to remove the need for EntityFrameworkCore.targets and GetEFProjectMetadata target. Fixes dotnet#23853
@paulomorgado How would this work with |
@fardarter, can you elaborate more? I don't understand what you're asking. |
My current
That gives me a layout as per: https://learn.microsoft.com/en-us/dotnet/core/sdk/artifacts-output So:
We have many projects referenced, but one startup project. Will this scenario be covered? And how would this be expressed in the current fixes? |
Querying properties from MSBuild execution will give you the exact values as during build. You can test Evaluate items and properties and display results of targets for yourself and see the results. What #34574 does is something like this:
|
I'm afraid I'm a bit out of my depth in translating that to a "yes, it will work" or "no it won't". Would you need to include the artifact path in the declaration here #23853 (comment)? Or is it derived? |
I am currently using artifacts path, and adding a Directory.Build.targets (at the solution root) like this <Project>
<!-- To use dotnet ef without 'msbuildprojectextensionspath' -->
<Import Condition="Exists('$(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).EntityFrameworkCore.targets')"
Project="$(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).EntityFrameworkCore.targets"/>
</Project> works as stated in #23853 (comment). |
At the moment, what I'm doing is roughly this:
And I don't have to make any changes to any project regardless of using artifacts output or not. |
dotnet ef migrations fail when using custom output paths and separate project/startup-projects
Hi folks,
I'm trying to get my projects setup in docker and I'm running into this error:
I used Brice's suggestion here #23691 (comment) and it works but only when everything is in a single project.
Other issues that are similar but I'm either missing a step or this is broken.
#23691
#12220
Example repo
I have a repo with 4 scenarios here: https://github.com/chris-garrett/EfTools. I removed docker for the time being since this is reproducible without it.
Steps
Verbose output
Provider and version information
EF Core version: 5.0.1
Database provider: Microsoft.EntityFrameworkCore.Sqlite
Target framework: .NET 5.0.101
Operating system: Ubuntu 20.04.1 LTS
IDE: command line
The text was updated successfully, but these errors were encountered: