sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
701 stars 231 forks source link

JetBrains - Rider Support #412

Open bbakermmc opened 6 years ago

bbakermmc commented 6 years ago

Any chance of getting Rider support?

EF.Reverse.POCO.Core.ttinclude(1,1) : error CS1519: Compiling transformation: Invalid token 'this' in class, struct, or interface member declaration
EF.Reverse.POCO.Core.ttinclude(1,12) : error CS1001: Compiling transformation: Identifier expected
EF.Reverse.POCO.Core.ttinclude(1,6) : error CS1520: Compiling transformation: Method must have a return type
EF.Reverse.POCO.Core.ttinclude(1,6) : error CS0501: Compiling transformation: 'GeneratedTextTransformation.GeneratedTextTransformation()' must declare a body because it is not marked abstract, extern, or partial
sjh37 commented 6 years ago

Thanks. I didn't know Rider support visual studio extensions. Once EF Core is out of the way, I shall take a look.

bbakermmc commented 6 years ago

They don't. But it was easy enough to reference the DLLs/file needed.

I made a copy of this file and put it in the same folder as the TT. https://github.com/aspnet/EntityFramework6/blob/master/src/EFTools/EntityDesign/TextTemplates/Includes/EF6.Utility.CS.ttinclude

Removed this line: <#@ CleanupBehavior Processor="T4VSHost" CleanupAfterProcessingTemplate="true" #>

Updated the path of these directories to my my VS2017 install folder:

<#@ assembly name="VERSIONED_VSCOMNTOOLS_ENV_VAR..\IDE\EntityFramework.dll" #>
<#@ assembly name="VERSIONED_VSCOMNTOOLS_ENV_VAR..\IDE\Microsoft.Data.Entity.Design.dll" #>
sjh37 commented 4 years ago

Good progress so far. Got a version of the generator working for Rider yesterday. Problems:

A Rider developer who specializes in T4 is going to contact me to see if these can be solved.

bbakermmc commented 4 years ago

For the double spaces are you using writeline and then a blank line after? I havent looked at t4 since they added it. I have both VS and Rider so so I reluctantly use VS at times for some things.

sjh37 commented 4 years ago

@bbakermmc Same identical code for both VS and Rider, two different outputs, one is neat and tidy, and one has blank lines. The following was generated using Rider. Rider Northwind.zip

I'll have a play and see why it's doing that when I get a moment.

bbakermmc commented 4 years ago

My question was about the tt file, are you using a writeline and then a new line after? image

matkoch commented 4 years ago

I think it's not worth investigating why there are additional empty lines. It's probably the implementation of the generator on Rider side, that is not ideal.

bbakermmc commented 4 years ago

Rider is usually pretty good about user feedback and fixes, you could post an issue.

matkoch commented 4 years ago

It has been reported. What I meant is that it’s not worth trying to fix/investigate here :)

On Tue 19. May 2020 at 18:47, bbakermmc notifications@github.com wrote:

Rider is usually pretty good about user feedback and fixes, you could post an issue.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/issues/412#issuecomment-630944117, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGGB7VJMQO7N75ZS3MXVHLRSKZYNANCNFSM4E5GYEKA .

sjh37 commented 4 years ago

I have created a temporary GitHub project for Rider so I can work with @kirillgla and get it working :-)

sjh37 commented 4 years ago

@kirillgla Double spacing is coming from rider executing the {{mustache}} templates within the generator. Note the extra \n in the image below.

Top = VisualStudio Bottom = Rider

image

I split the data from the {{mustache}} template by using:

Code.AddRange(code.Split(new[] { Environment.NewLine }, StringSplitOptions.None));
// Environment.NewLine = '\r\n'

However, this leaves lots of \n when running template in Rider. I could strip these out, but it would be good to know why it's happening and have it fixed at source within Rider.

sjh37 commented 4 years ago

In order to get the output looking the same, I've added some code to remove the extra \n generated in Rider. However, I'd still like to see Rider fixed.

See this changeset.

sjh37 commented 4 years ago

Added Rider bugs:

keeehlan commented 2 years ago

My team of 10 is very interested in having this working in Rider. I finally showed our Visual Studio users the way.

I'll take a look at the "temporary" project, but the readme is lacking instruction at the time of this comment.

sjh37 commented 2 years ago

Thanks @kehlankrumme git clone https://github.com/sjh37/EfrpgRider.git

  1. Open EFRPG-Rider.sln in Rider.
  2. Open RiderNorthwind.tt
  3. Edit the name of the database you want to use in line 19 Settings.ConnectionString
  4. Save
  5. Right click on RiderNorthwind.tt and select Run.
  6. Take a look at the code generated in RiderNorthwind.cs

I too have both VS and Rider, and running the output in Rider version 2021.2.1 I can see that some lines are still double spaced and some are normal. So there is a mix. It has to be something simple.

Inside of RiderNorthwind.tt search for Fix for Rider to see the 2 touch points I started to look at. I could be {{mustache}} processing related too.

sjh37 commented 2 years ago

Changing the template

        public override string Usings()
        {
            return @"
{{#each this}}
using {{this}};{{#newline}}
{{/each}}";
        }

to

        public override string Usings()
        {
            return @"{{#each this}}using {{this}};{{#newline}}{{/each}}";
        }

Stopped the multi-lines in Rider for the usings. So it look to be down to how the T4 template is being read by Rider as newlines are creeping in. I think this can be solved without too much trouble.

sjh37 commented 2 years ago

I have fixed the extra new lines being generated in the output. Last step is to sort out removing the use of EF6.Utility.CS.ttinclude within the template for VisualStudio as Rider does not like this.

keeehlan commented 1 year ago

Thanks @kehlankrumme git clone https://github.com/sjh37/EfrpgRider.git

  1. Open EFRPG-Rider.sln in Rider.
  2. Open RiderNorthwind.tt
  3. Edit the name of the database you want to use in line 19 Settings.ConnectionString
  4. Save
  5. Right click on RiderNorthwind.tt and select Run.
  6. Take a look at the code generated in RiderNorthwind.cs

I too have both VS and Rider, and running the output in Rider version 2021.2.1 I can see that some lines are still double spaced and some are normal. So there is a mix. It has to be something simple.

Inside of RiderNorthwind.tt search for Fix for Rider to see the 2 touch points I started to look at. I could be {{mustache}} processing related too.

Just getting back to this almost a year later.

Are there instructions for running this in a working setup?

For example, we are currently updating our entity model using an existing .tt file that has some customizations in it. It's already configured to run against our database and produce the POCOs in our solution.

We would like to be able to continue using this workflow, but in Rider instead of Visual Studio.

sjh37 commented 1 year ago

Hi @keeehlan It's a real problem. I would have to split the generator into two separate products, one for Rider and one for VisualStudio. This is required for old style .csproj files which list the files to compile, To edit those the generator makes use of EnvDTE which does not exist in Rider. .NetCore uses the new SDK style .csproj and does not use EnvDTE. I either have to split the product into two, two separate installers, or remove support for legacy .csproj projects. For now, you still have to open the .sln in Visual Studio and save the <database>.tt file to generate the files, then pop back to Rider.

savornicesei commented 6 months ago

@sjh37 What's the status of the Rider extension?

I believe support for legacy .csproj files can be dropped as any .NET framework 4.5+ project can be easily migrated to SDK-style projects (including those using EF6). MS already provides tooling to convert .csproj files (https://dotnet.microsoft.com/en-us/platform/upgrade-assistant, https://github.com/dotnet/try-convert - this requires .NET 5).

sjh37 commented 6 months ago

Excellent news, thanks @savornicesei. That means that old-style .csproj can be dropped, and Rider could now be supported!

savornicesei commented 6 months ago

@sjh37 You could release a v3.9.0-legacy extension (with Legacy in name or something appropriate) so that devs can still use v3.9 on legacy projects and move forward with the generator on SDK-projects only.