bennor / AutoT4

A zero-configuration extension for Visual Studio 2012+ which automatically runs your T4 templates at build time.
MIT License
11 stars 14 forks source link

ExecuteOnBuild File Property #3

Closed Mike-E-angelo closed 7 years ago

Mike-E-angelo commented 9 years ago

Love this extension... thank you! I was curious if you could possibly add an extension property on the files property list (call it ExecuteOnBuild) that allows you to turn on/off template execution on build on a file-by-file basis.

bennor commented 9 years ago

It's certainly something I can look at. I'm not sure what you mean by files property list though, are you talking about within the .csproj?

Mike-E-angelo commented 9 years ago

I mean the Properties Window when you select a .tt file in the Solution Explorer: https://www.dropbox.com/s/ljfqgl2grwwj38k/Properties.png?dl=0

It would be awesome to have an additional property there that says "Execute On Build."

:)

bennor commented 9 years ago

Not sure if I'll be able to set custom settings there, but will see what I can do.

Mike-E-angelo commented 9 years ago

Oh, it's definitely possible. 2 of the properties you see there (Custom Tool Parameters and Custom Tool Template) are added when you install T4 Toolbox... although, I'm not sure what they do or how to use them just yet. :P

bennor commented 9 years ago

:thumbsup:

Thanks. I'll suss it out and get a release out in a week or so (time permitting).

VagyokC4 commented 9 years ago

Has this been implemented yet? I would like to ONLY turn on this feature with certain .TT files, not just a blanket Auto Transform of all TT files.

bennor commented 9 years ago

I have implemented this but have not pushed it (or merged with master). I will do it on Saturday (or before then if I can).

Mike-E-angelo commented 9 years ago

Coooool. :)

bennor commented 9 years ago

@Michael-DST & @VagyokC4: If you feel like being testers for me, the VSIX is available now from the releases page for v1.1.0.

Let me know if you run into any problems (or if it just doesn't work for some reason).

malylemire1 commented 9 years ago

I've just tested the 1.1.0. VS2013 get restarted most of the time I edit a T4 with Run on build set to False. I've check the activity log and I get this error:

840 Error Editor or Editor Extension System.NullReferenceException: Object reference not set to an instance of an object. at .Ž.(Object , EventArgs ) at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent(Object sender, EventHandler eventHandlers)

I must mention that I use Tangible T4 editor but Transform on build is set to false. By the way thanks a lot for this new feature! It was just what I was looking for.

Maly

bennor commented 9 years ago

Okay, so clearly still needs work. I will have a look at it later today.

VagyokC4 commented 9 years ago

I've experienced no problems with 1.1.0. Its seems to be working as expected for me :+1:

bennor commented 9 years ago

There's definitely some sort of problem with it. In some circumstances it seems to completely crash VS, but I can't reproduce it reliably enough to figure out what's happening. The error above points to a missing null check somewhere but I can't find anything that I'm not checking.

VagyokC4 commented 9 years ago

What do you think about reversing the default logic.. so that Run on build defaults to false, and you selectively turn ON which files should be automatically transformed on build?

bennor commented 9 years ago

I'm not real keen on that. The great thing about it from my point of view is that you install it and in most cases don't have to think about it -- it just works without any configuration.

Mike-E-angelo commented 9 years ago

Make the default setting/behavior read from a setting in app.config?

Mike-E-angelo commented 9 years ago

Or actually... not app.config, but from the .csproj file.

VagyokC4 commented 9 years ago

Yes I can see that use case i.e. zero configuration, but I tend to want to 'first do no harm' and since TT files can automatically do a lot of stuff, I can also see the use case of 'Install AutoTT' and tell AutoTT which TT files to 'Run on Build'. Then installing AutoTT without any user interaction will 'first do no harm' and the end-user knows exactly what will happen when he compiles his project.

For example I had my 'EF.Reverse.POCO.Core' TT file hidden down a few folders and at first glance didn't see it... until I compiled my solution and ran into build errors.

If you're the only developer, this is probably less of an issue, but once you start working in teams, and because AutoTT is not a project based nuget, but installs into Visual Studio, and runs regardless of the project you're working on, I can see it having adverse affects if a team member does not realize this.

just my two pennies :)

malylemire1 commented 9 years ago

I've just found the problem. The finalizer in AutoT4Extender was calling dispose on an already finalized object. It's seem that calling dispose in the finalizer was also leading to twice disposal.

To correct the problem simply put this in the finalizer with a proper error message.

~AutoT4Extender() { try { if (_extenderSite != null) _extenderSite.NotifyDelete(_cookie); } catch { } }

You can remove the IDisposable implementation as it will never be called.

PS : I'm also in favor of the default BuildEvent.DoNotRun. I have 45 templates in my solution and it's a pain to set them all to DoNotRun. I also have to remember to set it when adding new templates.

bennor commented 9 years ago

Amazing, thanks. Do you mind submitting a PR for the bug fix?

I'm not keen on changing the default behaviour because it should just work for simple cases, but I can probably help you out. I'll add a 4th option Default or Inherit, then give you the option to change the default behaviour from the VS options dialog.

malylemire1 commented 9 years ago

Done with the PR.

Thanks would be great to have this setting.

bennor commented 9 years ago

The latest release should work, and has the additional option to change the default from "Before build" to "After build" or "Disabled".

https://github.com/bennor/AutoT4/releases/tag/v1.2.0

bennor commented 9 years ago

If nobody reports any problems with that build, I'll push it up to the gallery soon.

malylemire1 commented 9 years ago

Solution folders are not scanned for templates. Added a PR to support this. Added an issue : Templates are not scanned for dependent projects of active project in solution. When you build a project with dependent projects, the dependent projects should be scanned for templates. I'll do a PR when I have time, if you want to support this feature.

bennor commented 7 years ago

Closing since the core work is done and the one remaining issue has been raised independently.