I’m using VS2010 express to create a game built with xna. I’m trying to use t4 templates (to produce strongly-typed classes of content locations, thus using Level1Location = Content.Levels.Level1 instead of Level1Location = @"Content\Levels\Level1".
I’ve read that T4 templates aren’t properly set up in the express editions, but that if i create a file with extension .tt it should work. However when i create a .tt file in my XNA class library i get the following warning (and no code file):
The custom tool 'TextTemplatingFileGenerator' failed. Could not load file or assembly 'Microsoft.VisualStudio.ServicesProxy, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
I’ve searched and searched and can’t find anything useful. Has anyone encountered this problem before? Anyone know if a solution?
I’ve also tried changing the custom tool to TextTemplatingFilePreprocessor as suggested, however i get the same error.
EDIT: I’ve discovered that the issue is that it’s in an XNA project / library. It works fine in a normal class so my work around is to add a project to the solution just for the template. The question is still open though, can you get it to work within a XNA project?
Although i’ve posted this answer, i’m still looking for a simpler way of doing this (i.e. tt file in the XNA project its self)
In case anyone finds this page, here’s my work around:
Create a new (non-XNA) class library project.
Add a text file, renamed with the .tt extension.
Write your T4 code (see below).
In your XNA project, add an existing item, navigate to the created .cs file, and add as link.
Then, to ensure we always have the updated cs file, rightclick the XNA project and click project dependencies, then tick your class library project containing the .tt file.
Using the template code below, you can do things like Content.Load(Content.MyGameContent.Graphics.Textures.AwesomeTexture); You can also get folder names as strings with Content.MyGameContent.Graphics.Textures for example, thanks to a funky implicit string conversion operator.