Good news. The conversion is now two-way. Get the source code from GitHub. Make sure you have built MainDemo.Reports project.
You will find there are now two T4 transforms in the project. RepxToCSharp.tt is covered in the Part 1. It searches for any .repx files in the solution and converts the scripts into compilable C#.
The second transform is new. CSharpToRepx.tt copies any changes to the script part back into the original .repx files. Again, there are performance optimisations via checksums to prevent overwriting unchanged files.
1 2 3 4 5 6 7 8 9 10
Repx files with embedded scripts are now much more maintainable. You can correct syntax errors, refactor, version control, merge versions easily. You could even write unit tests against the code in the scripts.
Currently the easiest way of running these scripts is to open them and save them with
Ctrl+S. This is because T4 templates were originally designed as a Visual Studio tool.
In the future I’m hoping to improve the integration further. There are ways of including the transformations into the build instead, most of which are covered in a blog post by Mr T4, Oleg Sych. I like the idea of it being a NuGet package that can be easily added to any XAF project, but there’s a but I’ll need some more time to work out how best to achieve this.
Basic usage summary
Until then, here are some basic usage instructions.
- Add the T4 Toolbox extension to Visual Studio
- Add a copy of the MainDemo.Reports project to your own solution
- Make sure you build it before running the transforms
- Open RepxToCSharp.tt in Visual Studio.
- Save it with
Ctrl+Sto run the transform. It will search all the folders in your Solution for .repx files and add corresponding C# classes.
- Make any changes you like to the script section (anything outside of
// -- Start of embedded scripts --and
// -- End of embedded scripts --) will be ignored.
- Open CSharpToRepx.tt and run it with
Ctrl+S. The changes will be saved back to the corresponding .repx.
Even more power?
You may notice that if you reload the MainDemo.Reports project, you can now see
View in Designer in the context menu when you right-click on the .repx.cs file.
Let’s click it and see what happens. It opens directly in Visual Studio (like an
Now, this is all highly experimental. You can see there are some warnings… Also, there is no connection with XPO, so the Preview is always empty.
That said, it doesn’t seem like too much of a stretch to eventually allow far more Visual Studio integration for XAF reports…