Project is unable to find CSharpEntityTypeGenerator.
I've added Microsoft.EntityFrameworkCore.Design via NuGet, and in my .csproj file I have this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EPPlus" Version="4.5.3.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0-preview1.19506.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0-preview1.19506.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0-preview1.19506.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc4" />
<PackageReference Include="System.DirectoryServices" Version="4.7.0-preview1.19504.10" />
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="4.7.0-preview1.19504.10" />
</ItemGroup>
</Project>
Then, in my code, I'm trying to do this:
``` C#
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.Extensions.DependencyInjection;
// https://stackoverflow.com/questions/40728223/entity-framework-core-customize-scaffolding
namespace LaMP
{
public class EntityTypeGenerator : CSharpEntityTypeGenerator
{
public EntityTypeGenerator(ICSharpHelper helper) : base(helper) { }
public override string WriteCode(IEntityType type, string @namespace, bool useDataAnnotations)
{
var code = base.WriteCode(type, @namespace, useDataAnnotations);
var old = "public partial class " + type.Name;
var updated = "[System.CodeDom.Compiler.GeneratedCode]\n" + old;
return code.Replace(old, updated).Replace("namespace", "#nullable disable\n\nnamespace");
}
}
public class MyDesignTimeServices: IDesignTimeServices
{
public void ConfigureDesignTimeServices(IServiceCollection servicesCollection)
{
servicesCollection.AddSingleton<ICSharpEntityTypeGenerator, EntityTypeGenerator>();
}
}
public class ContextTypeGenerator: CSharpDbContextGenerator
}
```
Visual studio doesn't like CSharpEntityTypeGenerator or ICSharpHelper, and tells me I need to install Microsoft.EntityFrameworkCore.Design even though I've already done that.
EF Core version: Not sure how to tell
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.3.4
Remove IncludeAssets and PrivateAssets from the PackageReference
Thank you!
Most helpful comment
Remove IncludeAssets and PrivateAssets from the PackageReference