Closed drewnoakes closed 7 years ago
The readme suggests there should be a "Run on build" option for the .tt file. This is what I see:
I did test the extension with a new .NET Framework 4.6.2 project in VS 2017 and it all seemed okay, but it seems as though it'll have to work differently for the new project type. (I actually do very little .NET dev anymore so I haven't looked into the new format -- I'm assuming it's just for .NET Core?)
I just created a .NET Core project and nothing shows up. I'm assuming this is because none of the old VS interfaces are used for .NET Core. I'll have a look into it over the next few days and hopefully have something working by next week (provided it's possible). I did have trouble adding a text template to my project, as it didn't come up in any of the listed templates. I actually had to search for "template" to get it to come up.
Thanks for the rapid response.
The new project format was born with .NET Core in mind, but it allows you to target multiple frameworks from a single project, which is really nice. You don't have to target .NET Core at all, actually.
Beyond that I know very little about how it differs within the IDE from an extension author's perspective, sorry.
Seems to be a massively different format. I'm assuming that all the same hooks will be available, just on different objects.
In my testing I was seeing it auto-generate on build (perhaps you have "Disabled" set globally in the options and that's why you don't -- I confirmed that this setting is still influencing it), but I didn't see the template specific options show up in the properties (as you've pointed out in your screenshot above).
Interesting. I hadn't touched any settings:
I also don't have the option of creating a new T4 file from Add new item..., even searching for 'template' as you mentioned. I ran the VS2017 installer again to verify I had the T4 stuff installed, and it's there.
Hmm. I got it generating using a brand new NET Standard library. All I did was create the project, search for "template" in the Add Item dialog and add a new template. It regenerates on save (this is build into VS), and on build (AutoT4). I tested flipping the options to disabled and it stopped generating so it seems to be doing what it should.
Here's the .csproj
file (this was all generated -- I haven't hand edited anything):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Update="TextTemplate1.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>TextTemplate1.txt</LastGenOutput>
</None>
<None Update="TextTemplate1.txt">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>TextTemplate1.tt</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
</Project>
Would you mind following the above steps and seeing if that works. I'd just like to narrow it down to a project specific vs environmental issue.
Nice. It's working.
For future, here's what I think happened. I converted from VS2015 .csproj to project.json/.xproj. That format probably never supported T4, and I wasn't updating the .tt because it was stable. So the relationship between the generator and the two files was lost in the JSON model. Converting to newer .csproj couldn't know to re-inject that relationship. I did it manually based upon your .csproj file.
So I think this issue is invalid. If you want to post a summary of this on Stack Overflow I'll accept your answer.
Thanks very much for your help!
One small difference that might help others...
If you're generating a .cs file (or other type that needs to be compiled) be sure to use a Compile
element, not a None
.
Eg:
<ItemGroup>
<None Update="UnionTypes.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>UnionTypes.cs</LastGenOutput>
</None>
<Compile Update="UnionTypes.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>UnionTypes.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
Glad I could help!
(Reopening to track the fact that the options dialog isn't visible for these projects.)
At this stage I can't seem to figure out how to attach properties to items in the new project types. I asked in the Extend VS Gitter but got no response, so I'm going to park this for now. I'm not sure how many people will be using T4 with NET Core anyway.
As described here on Stack Overflow:
I installed AutoT4 1.2.1 and restarted VS, but it doesn't seem to update the output .cs file. Does this extension work with the newer .csproj project format?