Efcore: Azure Functions V2.0 with EntityFramework Core unable to create migration

Created on 12 Feb 2019  路  9Comments  路  Source: dotnet/efcore

_From @JoasE on February 12, 2019 8:53_

Steps to reproduce

  1. Create a new Azure Functions V2.0 project in visual studio
  2. Install:

    • Microsoft.EntityFrameworkCore v2.2.1

    • Microsoft.EntityFrameworkCore.Design v2.2.1

    • Microsoft.EntityFrameworkCore.SqlServer v2.2.1

  3. Add a model to the project (EG: User)
  4. Add a DbContext to the project and include a DbSet<User>
  5. Open the project in your favorite CLI.
  6. Type: dotnet ef migrations add Initial --verbose

Repro repo: https://github.com/JoasE/ReproDotnetEFError

Expected behavior

A migration is created.

Actual behavior

>dotnet ef migrations add Initial --verbose
Using project 'C:\Users\Joas\source\repos\TestApp\TestApp\TestApp.csproj'.
Using startup project 'C:\Users\Joas\source\repos\TestApp\TestApp\TestApp.csproj'.
Writing 'C:\Users\Joas\source\repos\TestApp\TestApp\obj\TestApp.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\Joas\AppData\Local\Temp\tmpE710.tmp /verbosity:quiet /nologo C:\Users\Joas\source\repos\TestApp\TestApp\TestApp.csproj
Writing 'C:\Users\Joas\source\repos\TestApp\TestApp\obj\TestApp.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\Joas\AppData\Local\Temp\tmpEABA.tmp /verbosity:quiet /nologo C:\Users\Joas\source\repos\TestApp\TestApp\TestApp.csproj
dotnet build C:\Users\Joas\source\repos\TestApp\TestApp\TestApp.csproj /verbosity:quiet /nologo

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.14
dotnet exec --depsfile C:\Users\Joas\source\repos\TestApp\TestApp\bin\Debug\netcoreapp2.1\TestApp.deps.json --additionalprobingpath C:\Users\Joas\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\Users\Joas\source\repos\TestApp\TestApp\bin\Debug\netcoreapp2.1\TestApp.runtimeconfig.json "C:\Program Files\dotnet\sdk\2.2.103\DotnetTools\dotnet-ef\2.2.1\tools\netcoreapp2.2\any\tools\netcoreapp2.0\any\ef.dll" migrations add Initial --assembly C:\Users\Joas\source\repos\TestApp\TestApp\bin\Debug\netcoreapp2.1\TestApp.dll --startup-assembly C:\Users\Joas\source\repos\TestApp\TestApp\bin\Debug\netcoreapp2.1\TestApp.dll --project-dir C:\Users\Joas\source\repos\TestApp\TestApp\ --language C# --working-dir C:\Users\Joas\source\repos\TestApp\TestApp --verbose --root-namespace TestApp
Error:
  An assembly specified in the application dependencies manifest (TestApp.deps.json) was not found:
    package: 'TestApp', version: '1.0.0'
    path: 'TestApp.dll'

Environment data

dotnet --info output:

.NET Core SDK (reflecting any global.json):
 Version:   2.2.103
 Commit:    8edbc2570a

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.103\

Host (useful for support):
  Version: 2.2.1
  Commit:  878dd11e62

.NET Core SDKs installed:
  2.1.4 [C:\Program Files\dotnet\sdk]
  2.1.102 [C:\Program Files\dotnet\sdk]
  2.1.103 [C:\Program Files\dotnet\sdk]
  2.1.104 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.400 [C:\Program Files\dotnet\sdk]
  2.1.401 [C:\Program Files\dotnet\sdk]
  2.1.402 [C:\Program Files\dotnet\sdk]
  2.1.500 [C:\Program Files\dotnet\sdk]
  2.1.503 [C:\Program Files\dotnet\sdk]
  2.2.103 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.3-servicing-26724-03 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

_Copied from original issue: dotnet/cli#10751_

closed-duplicate customer-reported

Most helpful comment

The reason for this error that Azure function does some organising to build artefacts with a certain structure and it moves dlls to subdirectory different from the project.dll.

To fix that you need to add PostBuildEvent.

By one of the following option:

1- Edit your project file by adding the following: (Work on windows only)

<Target Name="PostBuild" AfterTargets="PostBuildEvent"  Condition="'$(OS)' == 'Windows_NT' ">
    <Exec Command="copy /Y &quot;$(TargetDir)bin\*.dll&quot; &quot;$(TargetDir)*.dll&quot;&#xD;&#xA;" />
  </Target>

or

2- Right-click on your startup project, Properties -> Build Events tab and paste copy command

copy /Y "$(TargetDir)bin\*.dll" "$(TargetDir)*.dll"

image

and this script will copy dlls to the proper place.

All 9 comments

Moving to EF for initial investigation. It seems the tool was invoked correctly from the logs above.

Temporary workaround for anyone running into this issue until it is fixed

  1. Create a separate class library project in your solution targeting netcoreapp2.1.
  2. Install the nuget packages in the reproduce steps above in the class library project you just created instead of the Azure Functions project.
  3. Create your models and DbContext in the class library project aswell.
  4. Create a IDesignTimeDbContextFactory in the class library project. (see: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dbcontext-creation)
  5. Reference the class library project from your Azure Functions project.
  6. Run the dotnet ef migrations add command from within the class library project or use the --project argument to specify the class library's .csproj file.

Duplicate of #14084

Is anyone (@ajcvickers perhaps) aware of an open issue page where I can follow this issue (specifically concerning the '.deps.json' error) or of the official solution? Also, I'm sorry if there is something that I overlooked. I don't mean to waste anyone's time. Please assist and thank you ahead of time. :)

My current status

The issue

  • I receive a 'deps.json' error when I try to scaffold.
  • I tried creating the models and context manually then tried adding a migration and received the same error.
  • I tried it on Visual Studio 2017 with v2.1 and 2.2 of .Net Core. My EF project is in a different library; adding that in because it was a suggested work-around on another issue page.
  • I tried older versions and the most current versions (2.2.4 at the time of writing) of Microsoft.EntityFrameworkCore, Microsoft.EntityFrameworkCore.Design, and Microsoft.EntityFrameworkCore.SqlServer.
  • I even tried it, for what it's worth anyway, in the newly released VS 2019 and got the same error.

Research

All of the Github articles I can find about this issue (specifically concerning the '.deps.json' error), or at least those that are referenced in other articles, including this one, are closed and I didn't notice a solution, just that they were merged into something else. For example:

I noticed that a couple more issues pages are referenced as being replacements for possible duplicates. I read those and they are similar or may be where this issue stems from, but I didn't notice a reference to this specific error in either:

@tjorxwrynch As far as I am aware, the last two Azure Functions issues are the best place to follow up on this.

@tjorxwrynch As far as I am aware, the last two Azure Functions issues are the best place to follow up on this.

Thank you @ajcvickers!

Yes! I am getting this error as well tried EFcore 2.0.0 and latest 2.2.4 . This is offcourse trying to create an azure function, as a standalone console or app it works fine (well in 2.2.4 not testing in 2.0.0) .

Please help microsoft, has any one tried version 3?

BTW EF Core Power Tools plugin has allowed me to create the model

I have used this workaround and now I get numerous "dbset is defined in an assembly that is not referenced" errors in the AzureFunction project. So that leads you down another rabbit hole of issues, and another, until you just give up.

The reason for this error that Azure function does some organising to build artefacts with a certain structure and it moves dlls to subdirectory different from the project.dll.

To fix that you need to add PostBuildEvent.

By one of the following option:

1- Edit your project file by adding the following: (Work on windows only)

<Target Name="PostBuild" AfterTargets="PostBuildEvent"  Condition="'$(OS)' == 'Windows_NT' ">
    <Exec Command="copy /Y &quot;$(TargetDir)bin\*.dll&quot; &quot;$(TargetDir)*.dll&quot;&#xD;&#xA;" />
  </Target>

or

2- Right-click on your startup project, Properties -> Build Events tab and paste copy command

copy /Y "$(TargetDir)bin\*.dll" "$(TargetDir)*.dll"

image

and this script will copy dlls to the proper place.

Was this page helpful?
0 / 5 - 0 ratings