Skip to content
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

Custom file based templates Generation error #791

Open
Techhead33 opened this issue Feb 15, 2023 · 3 comments
Open

Custom file based templates Generation error #791

Techhead33 opened this issue Feb 15, 2023 · 3 comments
Assignees

Comments

@Techhead33
Copy link

Hello,
I am having issues with the V3 custom file base template generation. If I use the following settings without the custom templates I am able to generate my POCO classes:
Settings.DatabaseType = DatabaseType.SqlServer;
Settings.TemplateType = TemplateType.Ef6;
Settings.GeneratorType = GeneratorType.Ef6;
Settings.TemplateFolder = Path.Combine(Settings.Root, "Templates");
Settings.GenerateSingleDbContext = true;

After changing the setting to the below and putting the template files from https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/tree/master/_File%20based%20templates unchanged to verify custom templates are working, I am getting the message below the settings :
Settings.DatabaseType = DatabaseType.SqlServer;
Settings.TemplateType = TemplateType.FileBasedCore2-7; //There is no FileBased type or FileBased Type for Ef6 (not sure if this causes issues)
Settings.GeneratorType = GeneratorType.Ef6;
Settings.TemplateFolder = Path.Combine(Settings.Root, "Templates");
Settings.GenerateSingleDbContext = true;

Error:
// -----------------------------------------------------------------------------------------
// Failed to generate the code in GenerateCode() - Specified argument was out of the range of valid values.
/* at Microsoft.VisualStudio.TextTemplating8F788BA3CE2D0D30B566867D0AA92D8290002AE01038B8EC52857E133BBC9E8909795484B0A827DCABF22211CC4EFC9E8CDEC3BA7215DD0ADEB6A5A12F6C80AB.GeneratedTextTransformation.TemplateFactory.Create() in C:\Users\wdyer\Dev\VS\OPTIM.DataModel\EF.Reverse.POCO.v3.ttinclude:line 26040
at Microsoft.VisualStudio.TextTemplating8F788BA3CE2D0D30B566867D0AA92D8290002AE01038B8EC52857E133BBC9E8909795484B0A827DCABF22211CC4EFC9E8CDEC3BA7215DD0ADEB6A5A12F6C80AB.GeneratedTextTransformation.CodeGenerator..ctor(Generator generator, IDbContextFilter filter) in C:\Users\wdyer\Dev\VS\OPTIM.DataModel\EF.Reverse.POCO.v3.ttinclude:line 3465
at Microsoft.VisualStudio.TextTemplating8F788BA3CE2D0D30B566867D0AA92D8290002AE01038B8EC52857E133BBC9E8909795484B0A827DCABF22211CC4EFC9E8CDEC3BA7215DD0ADEB6A5A12F6C80AB.GeneratedTextTransformation.Generator.GenerateCode(IDbContextFilter filter) in C:\Users\wdyer\Dev\VS\OPTIM.DataModel\EF.Reverse.POCO.v3.ttinclude:line 5346
at Microsoft.VisualStudio.TextTemplating8F788BA3CE2D0D30B566867D0AA92D8290002AE01038B8EC52857E133BBC9E8909795484B0A827DCABF22211CC4EFC9E8CDEC3BA7215DD0ADEB6A5A12F6C80AB.GeneratedTextTransformation.Generator.GenerateCode() in C:\Users\wdyer\Dev\VS\OPTIM.DataModel\EF.Reverse.POCO.v3.ttinclude:line 5297*/
// --

@sjh37 sjh37 self-assigned this Feb 16, 2023
@Techhead33
Copy link
Author

I was able to get it working ... This comment was alittle misleading .. Settings.TemplateType = TemplateType.FileBasedCore2; // EfCore7, EfCore6, EfCore5, EfCore3, EfCore2, Ef6, FileBasedCore2-7. FileBased specify folder using Settings.TemplateFolder. I was putting TemplateType. FileBasedCore2-7 for the file based templates and when looking at the error line numbers in the ttinclude file I found out it should be FileBasedCore2 or FileBasedCore3 or FileBasedCore4 or FileBasedCore5 or FileBasedCore6 or FileBasedCore7 but there is not a case for FileBased. I am using Ef6 so that also was a bit confusing and was not sure if the other values would change the DBContext or anything else.

@sjh37
Copy link
Owner

sjh37 commented Feb 16, 2023

The template types you can use are:

public enum TemplateType
{
    Ef6,
    EfCore2,
    EfCore3,
    EfCore5,
    EfCore6,
    EfCore7,
    FileBasedCore2,
    FileBasedCore3,
    FileBasedCore5,
    FileBasedCore6,
    FileBasedCore7
}

I see what you mean; there is no file-based template for Ef6. This was because EF6 demanded the file manager use the EF6.Utility.CS.ttinclude to add/remove files to the visual studio project. If the project is an `SDK-style project, you can use the FileBasedCore* ones.

SDK style projects start with

<Project Sdk="Microsoft.NET.Sdk">

in the .csproj file

@sjh37
Copy link
Owner

sjh37 commented Mar 2, 2023

Released in v3.8.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants