NuGet-T4 file properties after installation

I am creating a NuGet package that supplies some T4 templates to the CodeTemplates directory. When I install the NuGet package, all T4 templates have the Custom Tool property set to "TextTemplatingFileGenerator". It is not right.

I know I can disable this by changing my registry so that new T4 templates are not added that way, but since this is a NuGet package, this is not an option.

I learned PowerShell, but it's hard for me to understand what I will do to achieve my goal.

I looked at the XML .csproj file and found this:

<None Include="CodeTemplates\AddController\Controller.tt"> <Generator>TextTemplatingFileGenerator</Generator> <LastGenOutput>Controller.cs</LastGenOutput> </None> 

If I remove the "TextTemplatingFileGenerator" from this node, then the file will work as I wish.

Where do I go next?

+4
source share
2 answers

I'm not sure there is a good way to do this. In a blog post, David Abbo wrote :

The last thing I mentioned about this model is that the .tt file is usually and not part of your project. Instead, he lives somewhere else, and only his exit becomes part of your project. Well, technically, the .tt file may be in your project for easy editing, but you need to remove the 'TextTemplatingFileGenerator custom tool, because you really do not want to do this yourself (this is certainly a failure with the user host).

It sounds like it's Visual Studio behavior when a .tt file is added to the project.

However, Scott Hanselman AddMvc3ToWebForms makes some changes to the GUID in the csproj file to add MVC functionality (Add Controller / Add View, etc.) ..) so that you can do something similar to its code and delete the section Generator for files in your package and reload the project?

+4
source

I had the same problem and solved it with "install.ps1" which runs every time the nuget package is installed or updated.

Your install.ps1 should look like this:

 param($installPath, $toolsPath, $package, $project) $addControllerFolder = $project.ProjectItems.Item("CodeTemplates").ProjectItems.Item("AddController") $addControllerFolder.ProjectItems.Item("Controller.tt").Properties.Item("CustomTool").Value = "" 
+2
source

All Articles