Entity Framework Code First for Plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Hello,

It appears that the use of Entity Framework with Code First is broken for Plugins on nopCommerce 4.0+. There are two issues I am facing, one of which I have a workaround. The first issue is that when you run "dotnet ef migrations add initial" it gives an error about not being able to find the deps.json file. This is because the deps.json file gets created inside Presentation/Plugins/Plugin.Name/ but it's looking in Presentation/Plugins/Plugin.Name/netcoreapp2.2/ for the deps.json. If you add the following to the csproj it fixes this problem:

<PropertyGroup>
   <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

The second problem I am having which I need help on appears to be related to how the ClearPluginAssemblies.proj gets run after build. When you want to run an EF command such as "dotnet ef migrations add initial" on the plugin project, it will build the project which will then run ClearPluginAssemblies.proj which will delete all the dependency DLL's since they exist in Presentation/Nop.Web/bin/Debug/netcoreapp2.2/ which is where they are used when running nopCommerce.

The problem is that dotnet ef commands don't know that and they keep saying missing DLL Nop.Core.DLL. I have tried everything I could find so far on how to make the "dotnet ef" commands look in that folder for dependecy DLL's but nothing has worked so far.  The only way I can get dotnet ef commands to work is by deleting the <Target> from csproj that runs ClearPluginAssemblies.proj while running the dotnet ef command and then to put that Target back before I run the project again.

Any assistance on how to get this to work would be great. Thanks!
4 years ago
chauhanmit22 wrote:
Hi,
If you could provide me with full stack trace?
Regards,


This is the error that "dotnet ef migrations list" spits out:

Error:
  An assembly specified in the application dependencies manifest (Nop.Plugin.Misc.Metro.deps.json) was not found:
    package: 'Nop.Core', version: '4.2.0'
    path: 'Nop.Core.dll'
4 years ago
I got the idea to change AfterTargets="Build" to AfterTargets="Run" and that works. Because dotnet ef commands will build the project but not run it so the dependencies will stay put. However, after you are done with your ef command you generally run the project again which will then run ClearPluginAssemblies.proj to clear out those files.

It's definitely not ideal but so far I'm coming up empty. I've tried:

Using --additionalprobingpath on dotnet command
Setting TRUSTED_PLATFORM_ASSEMBLIES
Setting APP_NI_PATHS
Setting APP_PATHS
Creating symbolic links
Setting up scripts to move all the files but that's not ideal either.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.