T4 templates do not generate output in new VS2017 csproj projects

I transferred the project project.json / .xproj to the new CS2017 .csproj format.

The project contains a T4 template file ( .tt ).

It does not restore its output when saving or assembling. The output .cs file is not .tt below the .tt file.

Is there something I have to do to make this work?

+5
source share
1 answer

.tt files only run VS automatically when saved. You can install AutoT4 so that they run before / after the build. (Keep in mind that at the moment there is a restriction with new .csproj files - the parameters are not displayed for them in the properties window.)

If you converted from the old project.json / .xproj , you may need to explicitly add the template to the project:

 <ItemGroup> <None Update="Foo.tt"> <Generator>TextTemplatingFileGenerator</Generator> <LastGenOutput>Foo.cs</LastGenOutput> </None> <Compile Update="Foo.cs"> <DesignTime>True</DesignTime> <AutoGen>True</AutoGen> <DependentUpon>Foo.tt</DependentUpon> </Compile> </ItemGroup> 

GitHub related issue

Edit

As mentioned in the comments below, you can do this quickly and simply by excluding and then including the template in your project.

+7
source

Source: https://habr.com/ru/post/1265802/


All Articles