Are there any alternatives to T4 templates and EnvDTE for cross platform asp.net 5 development? - code-generation

We currently use T4 templates to generate C# code files based on C# Code (Entity POCO's) and the EDMX (in older applications)
Moving to ASP.NET 5 with a view to support cross platform development, are there any code generation tools available that can read a projects class & meta data structures, and to generate C# files at design time, similar to T4 templates?

You can try Scripty - it is Roslyn based scripting.
Syntax highlighting for *.csx files works out of the box;
VS extension exists to process scripts on save;
MSBuild task exists to process scripts during buld process;
Script allows you to traverse a hierarchical model of the project;
Multiple files generation from single script is supported;

yeoman seems to be a good option. There exist some generators already for scaffolding asp.net 5 apps and you can create your own generators
It is cross platform and can be used on linux/mac/windows.

Even tt templates weren't supported earlier in asp.net-5 projects. It has been added recently (in Visual Studio 2015 Update 1).
The discussion is here: https://github.com/aspnet/Home/issues/272
And in the thread, Eilon said the Roslyn is the way to analyse the code and generate new ones... And he again said the ASP team has no immediate plan. So currently we have no solution from Microsoft.
But I did some search and didn't find any cross platform community tool to generate codes based on other codes. :(

Scriban worked for me as an alternative to replace T4 templates for generating unit test code. But it's a pure templating engine.

The new LeMP preprocessing engine for C# can be used as an alternative to T4 templates. May I ask what specifically you mean by "projects class & meta data structures"?

For this purpose I created a simple python
script called "autogen".
How it works: the script takes jinja template file (instead of T4) and data file (json) and generates one or multiple output files (e.g. C#, or any format) based on the template.
How it can be used (example): describe interface (methods, parameters) definition in json file, create *.j2 template files for C#, Java, Python, etc.. Then run autogen.py script and files for proxy/stub for all languages will be created.
This can help to create lot of similar code without copy/pasting and make code changes by simply changing single json file.
Moreover it can be integrated with build pipiline, msbuild (.net, .net core) and is cross-platform.

I have been looking into this same sort of thing, although not specifically with ASP.NET MVC but across project types as I move to .Net Core. I kept my T4 relying on EDMX early on. Which works out since EF7 moves beyond the file format in favor of code. Where I was planning on going with my code generation was a combination of ScriptCS and C# REPL. Roslyn complicates things for me a tad since there are no design time assemblies from what I understand. So the trick may be to understand and introspect cs files from within the project.

Related

Create, build and run solution (two projects: library and tests) with vscode

Is it possible now to create solution with Visual Studio Code editor (on Windows, assuming that potentially I should be able to run it on Mac)?
What I need:
App
|- Library (classes, business logic)
|- Tests
Later I want to add more projects to this solution, like asp.net website, helper services, etc. Right now wanna focus on business logic, tests and POCO only (with C#).
Is the future here already? And how to do that?
Yeah, the easiest is to target DNX (the cross platform runtime) and to use the DNX project system (project.json). A good read is this: https://dotnet.readthedocs.org/en/latest/dnx/overview.html
A good (but big) example is OmniSharp (https://github.com/OmniSharp/omnisharp-roslyn) which is developed by multiple people on all different platforms.

Packaging and Transforming Source Code Using NuGet

I'm currently working on a little pet project that takes a code file and deploys it using NuGet. I can currently replace the namespaces in the project using the $rootnamespace$ token and the .pp extension, but I'm curious if there is a better way.
My chief complaint is that I have to take code which builds correctly and transform it temporarily into something that no longer does so.
Is there a way for me to perform these transformations without having to alter my source code directly?
So, I created a very simple NuGet Preprocessor that looks at my solution and creates a shadow copy that has been tokenized and transformed to adhere to the NuGet standard. Works like a charm and now I can very easily deploy source files directly.

Has anyone used Enterprise Architect to reverse engineer perl?

I would like to reverse engineer a perl application in Enterprise Architect.
I have created perl as a New Language in Settings -> Code Generation Templates and I am guessing that I need a template for a new file, Attribute/Declaration, Operation/Declaration/Body.
I also guess that the operation should indicate "sub xxx" and the operation should indicate "x=y", however I am getting a bit stuck as to how to do this.
I can't be the first person to reverse perl so is there any Code Generation Templates out there?
First off, EA does not (in version 10.0.1009) natively support forward or reverse engineering of perl.
Secondly, these templates, which are part of the Code Template Framework, are for code generation only: they cannot be used for reverse engineering.
What you want instead is the Grammar Framework (see the help file under Extending UML Models -- MDG Technology SDK). This allows you to construct a grammar for a language, which specifies what UML elements EA should create when reading source files in that language.

Multiplatform MSBuild project file

I'm currently working on a project which source code should be as portable as possible; that is, the project (in C#, but it is not very relevant) represent an application that should be executed on Android (with Mono-Android), on iPhone (with MonoTouch) and WinMobile (with official Compact Framework). Without going into details, the corresponding MSBuild solution consists of an independent-platform library (from a source code point of view, at least) which declare various interfaces and classes that represent an abstraction of each feature that is not common to the various platform (i.e. the UI). In addition, there are a corresponding library that specialize (for each platform) the "base library"; the effective application executable is a program that uses the abstraction and the common standard libraries.
Developing on WinMobile and Android is not really a problem: Mono-Android add-in can be installed on VS 2010, so both platforms can be handled with MS VS.
Initially the solution was created in VS, so the initial configuration and the related projects (Android and WinMobile) are automatically generated.
After that I've imported the solution in MonoDevelop under Mac (the only platform that is officially supported by MonoTouch), and I've created the project for the iPhone library; switching the configuration to generate the assemblies (iPhoneSimulator) the "base library" was not possible to compile due to a missing project type configuration; specifically, the GUID used by MonoTouch for <ProjectTypeGuids> is {E613F3A2-FE9C-494F-B74E-F63BCB86FEA6}; adding this GUID I can now compile "base library" in MonoDevelop.
The problem arises when I try to re-import the solution in VS: since there's no Windows version of MonoTouch, VS cannot find the add-in for the specified project type, and the project doesn't load.
Looking to the specifications of MSBuild project file, it seems that there are tons of options that cannot be set or modified within the project/solution editor in VS; however the format is quite complicated and now I'm asking your help!
Is there a way to specify in the project file that a project type is present only if a particular configuration is selected independently to which is the environment I'm using?
The general approach is something like this; a condition that progressivly builds your property, referencing any value the property already may have:
<ProjectTypeGuids
Condition="'$(BuildingInsideVisualStudio)' != 'true'"
>;{E613F3A2-FE9C-494F-B74E-F63BCB86FEA6}"</ProjectTypeGuids>
<ProjectTypeGuids>{OTHER-GUIDS-HERE}$(ProjectTypeGuids)</ProjectTypeGuids>
This will detect the VS condition (when building) and omit the unkonwn guid. I'm not sure however if it will work when the project is opened, this property might only apply to building. There may be a similar "sentinal" property for building on Mono, and you can reverse the condition.
I solved an unrelated, but very similar issue of cross-platform development by excluding the files that presented themselves as cranky when going between Linux and Windows. I have my project under source control and utilized that to keep things working cooperatively.
http://www.aydabtudev.com/2011/05/what-goes-into-source-control-android.html
It's not a 1-to-1 for your issue, but it might give you clues/ideas on how to solve your problem.

ActiveReports Upgrade Error

I just upgraded from ActiveReports 2.0 to 3.0. All rpx files have been converted to *.vb files. The ActiveReports project has this class hierarchy:
*.vb with designer -> PrintBase.vb -> ActiveReport3
When I opened any of the *.vb files, I got this error:
The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: xxx --- The base class 'PrintBase' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.
Call stack:
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)
Then I went through PrintBase.vb. There was no compile error. Then I modified one of the *.vb files to this:
Hello.vb -> ActiveReport3
The designer worked without any problems. The PrintBase has quite a bit of code. To simplify the debugging, I created a new .vb file called BasePrint that inherits from ActiveReport3. So, the hierarchy is back to:
Hello.vb -> BasePrint -> ActiveReport3
Then I saw the same error above again. It seems like AR3 designer does not allow .vb files to inherit from a base class according to my debugging. But I am not quite sure. BTW, the ActiveReports project is vb.net. There are other C# projects under a VS 2008 project solution. Is the mixing of VB.NET projects and C# have anything to do the miagration / upgrade process?
Thanks.
Indeed, the class-style inheritance was not supported by the upgrade utility in the ActiveReports 3.x designer. However, after an upgrade is complete you should be able to put the base class bad (the way that you described) and the designer should safely ignore it. If you're still having problems try to close the project, do a clean (delete the old assemblies that might be referncing the old PrintBase class) & close visual studio and reopen it again to get a fresh start.
You can find more information about upgrading reports from ActiveReports 2.x to ActiveReports 3.x at the following page: link text
However, it seems you are using inheritince in this case to share some utility methods and maybe some state (e.g. in class-level fields maybe). For this it is best if you have your reports inherit directly from ActiveReport3 and use "BasePrint" as a sort of utility class that your reports call functions in. Normally this has no disadvantage other than having to prefix the method calls with the name of the corresponding BasePrint instance/variable name and it simplifies dealing with ActiveReports designer in the scenario you describe.
However, ActiveReports does support a visual inheritence that allows a base report to share controls with a derived report. There is more information on how to use this feature at the following location: http://www.datadynamics.com/Help/ARNET3/ar3tskInheritance.html. However, I want to stress that this is a different style of inherience than you are using so it may not be applicable to what you need.
Also, you should try to convert again without having a combined solution with C# and VB projects. I don't know that this is a problem but it is certainly not the most common way the converter is used and may be complicating things.
Finally, you should be aware that ActiveReports 6 is now available and you may want to consider trying out that version.
If you continue to have any problems please contact our support team at support#grapecity.us.com or use our public forms that have many ActiveReports experts monitoring them every day at the following links:
http://www.datadynamics.com/forums/73/ShowForum.aspx - ActiveReports 3 Forum
http://www.datadynamics.com/forums/82/ShowForum.aspx - ActiveReports 6 Forum
Scott Willeke
GrapeCity / Data Dynamics