Visual Studio Templates - custom parameters

前端 未结 2 1974
终归单人心
终归单人心 2021-01-28 18:02

I am using VS 2015 templates to create a project for me, within my C# classes I have substitutions like $projectname$ and they work great if I name my project like

2条回答
  •  孤城傲影
    2021-01-28 18:28

    I had exactly the same problem a week ago. I just needed some customed variables inside of my template, which would resolve in $projectname$ upper case and one other in lower case. Things like that.

    It turned out for me to be the most effective and flexible way to develop my own project wizard using VS' custom wizard template.

    Unless JavaScript & HTML is not a no-go for you, it is pretty easy to have some string manipulation on variables like $projectname$ there.

    Once you set it up, go in default.js and edit in function

    function onFinish()
    {
        ...
    
        var prjName = wizard.FindSymbol('PROJECT_NAME');
    
        wizard.AddSymbol('PROJECT_NAME_WITHOUT_DOTS', prjName.split('.')[0]);
    
        ...
    }
    

    split('.') removes all dots and devides it into an array of strings. With [0] you select just the part up to the first dot.

    In your template files you can then address the symbol PROJECT_NAME_WITHOUT_DOTS with the following syntax:

    class [!output PROJECT_NAME_WITHOUT_DOTS] {
        ...
    }
    

提交回复
热议问题