之前的合作社创建了一个自动生成的html文件,其中包含用户输入的数据。我试图复制这个,但我正在努力找到一种方法来允许.tt文件具有插入数据所需的范围。
他的.tt文件的输出如下所示...请参阅下面的.tt文件。
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version: 14.0.0.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
// ------------------------------------------------------------------------------
namespace myNamespace
{
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System;
/// <summary>
/// Class to produce the template output
/// </summary>
#line 1 "C:/path to .tt file"
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")]
public partial class Template : TemplateBase
{
#line hidden
/// <summary>
/// Create the template output
/// </summary>
public virtual string TransformText()
{
this.Write("<html>\r\n<head>\r\n\t<title>Telematics Configuration Job - ");
#line 8 "C:/file path to .tt file"
this.Write(this.ToStringHelper.ToStringWithCulture(Job.JobNumber));
#line default
#line hidden
this.Write(@"</title>
<link rel=""stylesheet"" type=""text/css"" href=""JobDatasheetStyles.css"">
</head>
<body>
<div id=""Page"">
<div id=""Document_Header"">
<h1 class=""Document_Header_Item"" id=""asdf"">
<span class=""Header_Text"" id=""asdf_Header_Text"">asdf Industries Inc.</span>
</h1>
<div class=""Document_Header_Item"" id=""Datasheet_Name"">
<span class=""Header_Text"" id=""Datasheet_Name_Text"">Telematics Configuration Job Datasheet</span>
</div>
<div class=""Document_Header_Item"" id=""asdfdd"">
<span class=""Header_Text_Sub"" id=""asdfas"">Manufactured with asdfversion ");
不完整,但它只是完成了html文件。请参阅下面的.tt文件。
<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<html>
<head>
<title>Telematics Configuration Job - <#= Job.JobNumber #></title>
<link rel="stylesheet" type="text/css" href="JobDatasheetStyles.css">
</head>
<body>
<div id="Page">
<div id="Document_Header">
<h1 class="Document_Header_Item" id="asdf">
<span class="Header_Text" id="asdf">asdf Industries Inc.</span>
</h1>
<div class="Document_Header_Item" id="Datasheet_Name">
<span class="Header_Text" id="Datasheet_Name_Text">Telematics Configuration Job Datasheet</span>
</div>
<div class="Document_Header_Item" id="asdf">
答案 0 :(得分:0)
我发现在线的所有教程都没有提到我使用RunTime TextTemplate而不是TextTemplate。