Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9226843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:55:35+00:00 2026-06-18T04:55:35+00:00

i made a T4 template in visual studio recently and started encountering a problem

  • 0

i made a T4 template in visual studio recently and started encountering a problem i cant find the reason for.
whenever i edit the template and run it then it performs as expected. if i run it again without editing the template the content is output duplicate. if i run it again, without editing, it adds another duplication, resulting in seeing the output 3 times. and so on.

<#@ template debug="true" hostSpecific="true" #>
<#@ output extension=".txt" #>
<#@ Assembly Name="System.Core" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #> 
<#
    input.Add("data1");
    input.Add("data2");
    foreach(var data in input)
    {
#>
<#=data#>
<#
    }
#>
<#+
    static List<string> input = new List<string>();
#>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:55:36+00:00Added an answer on June 18, 2026 at 4:55 am

    after some logical thinking i concluded that the template was somehow ‘remebering’ my inputs. and then i thought that it might be the static class feature i inluded for collecting my inputs. removing it fixed the problem! how it came about that there was a static in the first place was because i first tested most of the complex initialization logic in a console application and just copied it to the template.

    conclusion:
    so it seems that visual studio builds a library from your T4 template when you save it and also loads it into an appdomain and then executes it. and it will reuse this loaded library until you edit yout template. and thats how this static variable remebered the inputs from the previous time the template was run – its still alive.

    as a side note, next time i will test my initialization code inside a class instance instead of next to static void main()!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently i made two template classes,according to the book Modern C++ design. I think
I'm trying to create a custom item template for Visual Studio that creates multiple
I want to create a Visual Studio 2010 Project Template, which is essentially a
I'm using the visual studio POCO Template for the Entity Framework, so far it
I recently developed an interop user control in .NET (Visual Studio 2008, project targetting
I made myself a template for all JSPs in my webapp that keeps things
I made up a template to show all the fields and values from a
I've made some function that generates an email template. Code it generates is pure
I have made a custom suface button according this example: <Button> <Button.Template> <ControlTemplate TargetType=Button>
I'm currently working on a Visual Studio integration project for VS2010 (a custom highlighter)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.