Giter Club home page Giter Club logo

t5's Introduction

T5

Build Status Build Status
NuGet MyGet
NuGet MyGet

T5 is an open-source implementation of the T4 text templating engine for .NET Core based on and derived from Mono.TextTemplating.

Usage

The TextTransform tool can be installed into a .NET Core 2.0 project by adding a <DotNetCliToolReference> node to the project file, as shown below:

  <ItemGroup>
    <DotNetCliToolReference Include="T5.TextTransform.Tool"
                            Version="1.1.0-*" />
  </ItemGroup>

Set the Version attribute value to the desired version of the tool.

The reference will cause the tool to be installed whenever dotnet restore is run next. It can then be used as follows:

dotnet tt TEMPLATE

Replace TEMPLATE with the path to your T4 template.

For full help on usage, run:

dotnet tt --help

When you run dotnet tt, make sure that you do so from the project's directory set as your shell's current directory otherwise dotnet will complain with an error message along the lines of:

No executable found matching command "dotnet-tt"

Building

Make sure that the .NET SDK Core 2.0 is installed.

To build the project, run build.cmd on Windows or build.sh on macOS or a supported Linux distribution.

To run the unit tests, run test.cmd on Windows or test.sh on macOS or a supported Linux distribution. The test script builds the project before running the unit tests.

To build NuGet packages for distribution, run pack.cmd on Windows or pack.sh on macOS or a supported Linux distribution. The packaging script builds the project but does not run unit tests. The script accepts a single optional argument that is used as the version suffix of the packages, e.g. beta1.

t5's People

Contributors

alanmcgovern avatar atifaziz avatar bittercoder avatar christopher-vonblum avatar fredpointzero avatar garuma avatar jstedfast avatar mhutch avatar mkrueger avatar mnaoumov avatar mrward avatar piotrzierhoffer avatar rolfbjarne avatar slluis avatar therzok avatar tomkcook avatar xplicit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

t5's Issues

Tools

Hi,

Dose this have support vs2017 

Critical Memory Leak

When i try to generate code from compiled templates i'm running into a critical memory leak.
The following code is for demonstration only.

var template = File.ReadAllText("Template.txt");

Parallel.For(0, 1000, (i) =>
{
    var compiledTemplate = engine.CompileTemplate(template);
    var result = compiledTemplate.Process();
});

Btw: All higher level template processing is effected too.

Tools

Hi,

Dose this have support vs2017 

Generation error if parameter directive is used

Environment

  • T5.TextTransform.Tool = 1.1.0

Steps to reproduce

  1. generating new c# console project
  2. add T5.TextTransform.Tool-1.1.0 to PackageReference
  3. create tt
  4. run dotnet tt -a Namespace=abc

the tt file is following.

using System;

<#@ import namespace="System" #>
<#@ parameter Type="System.String" name="Namespace"#>
<#
    var ns = Namespace;
#>
namespace <#=ns#>
{
}

Exepcted Result

output following cs file.

using System;
namespace abc
{
}

Actual Result

compilation was failed and output following error message.

Processing '.\hoge.tt' failed.
(66,34): ERROR The type or namespace name 'Remoting' does not exist in the namespace 'System.Runtime' (are you missing an assembly reference?)

.NET Remoting is not currently supported in .NET Core, but t4's implementation seems to use it in processing parameter directive.

Tools

Hi,

Dose this have support vs2017 

Tools

Hi,

Dose this have support vs2017 

Having trouble with syntax

I'm currently trying to execute code in the template and having all sorts of trouble

dotnet tt CodeGen\test.ttx -o ClientApp\src\testing\httpMock\test.tt -r Web.dll -P=bin\Debug\netcoreapp2.2 -P=bin\Release\netcoreapp2.2 -u=Web -u=Web.CodeGen

Is giving me dotnet : No input file specified. where as I've gotten it to output with fewer arguments.

<#@ assembly name="Web" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="Web.CodeGen" #>

<#@ output extension=".tt" #>
<#

var darkHost = BlackMagic.DarkRitual();
var tome = new BlackMagic(darkHost.Services.CreateScope().ServiceProvider);
foreach(var varTuple in tome.AllVarTuples)
{ #>
   export const <#= varTuple.Name#> = <#= varTuple.Val#>;
<# } #>

Executing just dotnet tt on the file is giving

dotnet : (0,0): ERROR The type or namespace name 'Web' could not be found (are you missing a using directive or an assembly reference?)
At line:1 char:1
+ dotnet tt CodeGen\test.ttx -o ClientApp\src\testing\httpMock\test.tt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: ((0,0): ERROR Th...bly reference?):String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
CodeGen\test.ttx(10,15): ERROR The name 'BlackMagic' does not exist in the current context
CodeGen\test.ttx(11,15): ERROR The type or namespace name 'BlackMagic' could not be found (are you missing a using directive or an assembly reference?)

I'm not sure how to resolve these problems given the help file, as offering too many, or certain, parameters seems to just arbitrarily prevent using it at all?

Publish as a .NET Core (2.1) Global Tool

T5.TextTransform.Tool is currently available for .NET Core as dotnet-tt using the CLI tools extensibility model. .NET Core 2.1 introduces .NET Core Global Tools but which seems incompatible. Running dotnet tool install -g T5.TextTransform.Tool ends up in the following error:

error NU1212: Invalid project-package combination for T5.TextTransform.Tool 1.1.0. DotnetToolReference project style can only contain references of the DotnetTool type 
dotnet : The tool package could not be restored.
At line:1 char:1
+ dotnet tool install -g T5.TextTransform.Tool
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (The tool package could not be restored.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
Tool 't5.texttransform.tool' failed to install. This failure may have been caused by:

* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by th
is name was found, but it was not a .NET Core tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.

Consider making T5.TextTransform.Tool available as a .NET Core Global Tool (so it can be run like dotnet tt) without compromising the existing ability to use on .NET Core 2.0, especially as a per-project tool via <DotNetCliToolReference>.

Tools

Hi,

Dose this have support vs2017 intelisense or syntax heilight ?

Template using VB fails with compilation errors

Trying to use the following template:

<#@ template language="VB" #>
<#@ output extension=".txt" #>
Hello World

Results in:

PS C:\T4Test> dotnet tt Test.tt
Processing 'Test.tt' failed.
(0,15): ERROR ; expected
(0,56): ERROR ; expected
(1,76): ERROR Syntax error, '(' expected
(3,21): ERROR Syntax error, ',' expected
(3,43): ERROR Syntax error, ',' expected
(3,44): ERROR Tuple must contain at least two elements.
(3,49): ERROR Syntax error, ',' expected
(4,10): ERROR Syntax error, ',' expected
(4,11): ERROR Syntax error, ',' expected
(4,33): ERROR Identifier expected
(4,42): ERROR Syntax error, ',' expected
(6,9): ERROR Preprocessor directive expected
(7,16): ERROR Identifier expected
(7,16): ERROR Syntax error, ',' expected
(7,17): ERROR Type expected
(7,17): ERROR Tuple must contain at least two elements.
(7,17): ERROR ) expected
(7,17): ERROR Identifier expected
(7,17): ERROR Syntax error, ',' expected
(7,31): ERROR Syntax error, ',' expected
(7,64): ERROR Identifier expected
(7,64): ERROR Syntax error, ',' expected
(7,65): ERROR Type expected
(7,65): ERROR Tuple must contain at least two elements.
(7,65): ERROR ) expected
(7,65): ERROR Identifier expected
(7,65): ERROR Syntax error, ',' expected
(7,68): ERROR ; expected
(7,106): ERROR ; expected
(7,106): ERROR Member definition, statement, or end-of-file expected
(9,9): ERROR Preprocessor directive expected
(10,48): ERROR Syntax error, '(' expected
(11,16): ERROR Syntax error, ',' expected
(13,21): ERROR Syntax error, ',' expected
(13,35): ERROR Syntax error, ',' expected
(13,36): ERROR Tuple must contain at least two elements.
(14,14): ERROR Syntax error, ',' expected
(14,15): ERROR Syntax error, ',' expected
(15,8): ERROR Syntax error, ',' expected
(16,4): ERROR Syntax error, ',' expected
(16,9): ERROR Identifier expected
(16,9): ERROR Syntax error, ',' expected
(18,6): ERROR Syntax error, ',' expected
(18,42): ERROR Tuple must contain at least two elements.
(18,43): ERROR Identifier expected
(18,43): ERROR ) expected
(18,43): ERROR ; expected

Changing the language to C# makes it work as expected.

compilation err

Hi, thanks for your project.
When I try

<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ import namespace="Newtonsoft.Json" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="Microsoft.AspNetCore.Http" #>
<#@ import namespace="Microsoft.AspNetCore.Mvc" #>
<#@ import namespace="Microsoft.AspNetCore.Mvc.ApiExplorer" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="Microsoft.AspNetCore.Mvc" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="System.Threading.Tasks" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="System.Runtime" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Xml.Linq" #>
<#@ Assembly name="EnvDTE" #>
<#@ Assembly name="Microsoft.AspNetCore.App" #>
<#@ output extension=".ts" #>
<# /* Environment.CurrentDirectory */ #>

//AUTOGENERATED DO NOT EDIT THIS FILE <#= DateTime.Now.ToString() #>

I get

(0,0): ERROR The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
(0,0): ERROR The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
(0,0): ERROR The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
(0,0): ERROR The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.