-
Notifications
You must be signed in to change notification settings - Fork 601
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
T4 Templates don't work in asp.net core #368
Comments
I would love to port PetaPoco to .net core, and hopefully one day I will, however, it comes down to time. In the .net core world, the T4 schema generation would be replaced with the a new tool which would be added to the tools section of the project file. See tools |
I see some posts at large regarding code generation for .net core. It sounds like you have a clear idea of your approach given the time. I have some time if you're willing to outline the approach. |
Any updates on this? I've just set up a new PetaPoco project in Net Core 2, and it was pretty easy to get it working. Seems like a lot of the stuff that was prompting a rework in Core 1 has been re-added in 2. In PetaPoco.cs (approx line 205) and PetaPoco.Core.ttinclude (approx line 349), replace:
with:
Ensure I am also getting an ugly error when building the T4 templates in VS2017. It appears that these are officially supported in VS2017, but it's choking with a SerializationException in EnvDTE.Project dteProject = (EnvDTE.Project)activeSolutionProjects.GetValue(0); I can still build the T4 template if I right click and choose the 'debug T4 Template' option - that seems to work. And at times the regular build fixes itself for a while, but then later starts throwing this exception again. Pretty flaky. Just wondering two things:
|
I have T4 working in vs2017 modified for NPoco two weeks ago. I notice the same error on the first save. But usually after the second save, it generates my pocos each time. Scripty is a tool I was considering--to replace T4 files with csx script. But now that's moot. |
Yeah I don't think Scripty can do the database access in the same way, or at least not without a lot of gymnastics. The T4 templates are surprisingly flexible. |
hi, do you want to try this tool PetaPoco.DBEntityGenerator I just built? I've ported the T4 template into this tool. It supports net core. |
I note I have found a fairly simple mod that fixes the T4 generation, I've been doing it happily for some months now. It's a bit of a hack, I have been waiting to find the time to review it and make something more graceful. |
@hippasus Trying out your generator tool and looks good. I was going to start from scratch and maybe use something like |
@picasso566 Yeah, I have been using the T4 templates since SubSonic 3, but frankly I have to say they suck. They are fine if nothing changes and you leave them alone, but if you change them they are extraordinarily hard to debug if there are any problems (I end up applying changes a few lines at a time, because otherwise it's impossible to work out what broke and why). |
@hippasus I'll have a look at your tool, I'm leaning towards an open source solution so I have some assurance of long term viability. |
All I know is, one of the big draws for me to PetaPoco (for the last 10 years in my case) was the auto generated classes and decorators in the T4 templates. One of the reasons I've been using Petapoco over Dapper or something else. They really speed things up for me. |
I know people love the class generation T4 stuff. I'd like to have a good solution here, but it's not the easiest thing to solve without a fair bit of time and effort. Although I haven't used it yet, the generator from @hippasus looks awesome and seems to support all the major DBs, so it gets my vote. |
If you're using netcore, don't forget EF can reverse eningeer now too. I don't mind EF Core (>= 3.1) and it's much better than EF 6. If you configure it correctly, you can get some good preformance out of it. |
Another approach I've had success with is using the "LoadTables()" function from the old version, and pushing the result of that through templates created in Razor syntax, using https://github.com/Antaris/RazorEngine. Unfortunately RazorEngine doesn't have a maintainer so is stuck in full .net framework. Razor has some quirks when used outside of its natural environment, but will at least offer up intellisense for most things. |
@iadaz ... and the wheel comes full circle yet again! that is exactly how SubSonic 2 did it (well, it wasn't a razor engine, but it was the ASP NET rendering engine). Then we 'upgraded' to T4 in SubSonic 3 in about 2009. |
I believe origin of the T4 templates PetaPoco uses is SubSonic 😂 Applogies, @6pac - whilst hunting around the issues trying to find the Tools link, I realised I never answered you in #502 ☹ 🤔 I guess one path forward is Razor templates possibly using RazorLight, and making a PetaPoco T4 replacement Tool. I figure the use case would be to include a default template and allow people to reference their own. @hippasus would you be open to a PR adding this? |
no worries. I've been way too busy for way too long. Hopefully this year I'll have time to sit down and test out the new dotNet Core features with MySql,, Sqlite and MSSQL (I'm actively using all three), and integrate them into my dev env, and assess T3 alternatives. I have some outstanding changes to feed back as well, regarding optionally removing reflection dependencies to allow PetaPoco to run on iOS under Xamarin. |
I've been wanting to remove this for a long time. @Shazwazza, a dev who works on Umbraco, said they removed it in favour of delegates and believe it's a pref improvement, which I tend to agree with. Even if there was a slight loss of pref (which I doubt), it's still IMO a better path, as it reduces complexity and improves usage scenarios. Ref PR 149 |
I can make a PR for what I've done. I've waited (a) because it was a quick hack to solve an unexpected roadblock and (b) to see if there were any more issues. I noted in the issue at the time that the error is at runtime, not compile time, so putting in an #ifdef or similar is an option to keep the original code as an option if that's desirable for some scenarios. However it also means that I may not have fixed some code paths that I don't use. |
If you submit a PR, I can run it across the integration tests to try find any missing edge cases |
The above tool will work, however it is being blocked because of the inclusion of EnvDTE and System.Windows.Forms. I believe if we replace those two dependencies and use netstandard replacements, the T4 templates will work cross platform. For example: public EnvDTE.Project GetCurrentProject() {
IServiceProvider _ServiceProvider = (IServiceProvider)Host;
if (_ServiceProvider == null)
throw new Exception("Host property returned unexpected value (null)");
EnvDTE.DTE dte = (EnvDTE.DTE)_ServiceProvider.GetService(typeof(EnvDTE.DTE));
if (dte == null)
throw new Exception("Unable to retrieve EnvDTE.DTE");
Array activeSolutionProjects = (Array)dte.ActiveSolutionProjects;
if (activeSolutionProjects == null)
throw new Exception("DTE.ActiveSolutionProjects returned null");
EnvDTE.Project dteProject = (EnvDTE.Project)activeSolutionProjects.GetValue(0);
if (dteProject == null)
throw new Exception("DTE.ActiveSolutionProjects[0] returned null");
return dteProject;
} Could be replaced with something like: I understand this bubbles through, but all we need are names of folders and files which should be possible without EnvDTE dep. |
I've tried to adjust things but have not had any success with asp.net core, vs2017 rc3.
Is there a plan?
The text was updated successfully, but these errors were encountered: