views:

33

answers:

2

Hi,

I'm trying to create a T4 template to generate a class for a specific task I need. However, something is broken with its output.

The output file contains random garbage characters even when the .tt file is blank. I'm thinking it's something to do with the character encoding on the .tt file, maybe.

I can successfully add a code generation item to an edmx file and it will generate fine unless I make a change to the tt file, save, revert the change, resave. The output becomes garbage again.

Haven't been able to find anyone else experiencing this issue.


Example: TextTemplate.tt

<#@ template debug="false" hostspecific="false" language="C#" #>

Output file: TextTemplate.cs

믯㲿䀣琠浥汰瑡⁥敤畢㵧昢污敳•潨瑳灳捥晩捩∽慦獬≥氠湡畧条㵥䌢∣⌠ാ

Ideas, anyone?

Thanks,

Carl

A: 

Have a look at the output file in binary. It's possible that it's actually in UTF-8 or ASCII, but that Visual Studio thinks it's in UTF-16. Can you post the first few characters of what you'd expect, and their binary output? (If you could post the binary input as well, that would help.)

Jon Skeet
error generating output, I believe it says. Not 100% sure.I manually opened the file, saved it as unicode and run custom tool again and I got the message i just suggested. Re-save and it's broken again. Notepad reports it as a UTF-8 file, which is apparently the default of VS. Not sure where to proceed from there.
Carl
I also tried a couple of directives that set its output to UTF-8, too. In the tt code, I mean. No help
Carl
@Carl: Don't open it in a text editor and save it as a different encoding - open it with a *binary* file editor and post the raw bytes of the contents. But if the tool is giving an error message, then you should post that exact error message] too. You didn't mention that before.
Jon Skeet
That's because I discovered the error message from further experimentation between our posts. :) Thanks for helping confirm for me it had something to do with the encoding.
Carl
A: 

Managed to work around this by doing Right Click -> Open With -> Source Code (Text) Editor With Encoding. Picked up fine with Encoding: (Auto-Detect)

Carl