I want to define where on hdd will .cs file going to be generated from a t4, programmaticaly

StackOverflow https://stackoverflow.com/questions/23311734

  •  10-07-2023
  •  | 
  •  

문제

Okay, so everything is said in the title. I couldn't find anywhere on the web how to do this. I need this since we want to generate a .cs file elswhere, and not in the default destination.

도움이 되었습니까?

해결책

I managed to solve a similar task with the following technic.

Install the T4 Toolbox extension to Visual Studio (probably not needed, I'm not sure).

Wrap your template content into a class like this:

<#+
public class MyTemplate : CSharpTemplate
{
    public MyTemplate ()
    {
    }

    public override string TransformText()
    {
        base.TransformText();       
#>
 // PUT YOUR TEMPLATE RENDERING HERE
<#+
    }
}
#>

Then create another template file and call this template explicitly. There you can configure the output parameters.

<#
    var mytemplate = new MyTemplate();
    mytemplate.Output.Project = @"MyProject.csproj";
    mytemplate.Output.File = @"MyFileRelativeToProjectFolder.cs";
    mytemplate.Render();    
#>

Please refer to this article for further details.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top