Tips & Tricks: CodeSmith Template Encoding.

There may be a time when you need to use Extended ASCII Codes in your CodeSmith templates. If you have already tried using them into your template you have more than likely ran into the following problem. When a user first creates a template an Encoding attribute is not added by default to the CodeTemplate directive. So when a user starts adding characters in the Extended ASCII range, they will run into the following problem without first setting the encoding attribute. Below is an example of using Extended ASCII characters in a template.

If you don't add the Encoding Attribute to your template before saving, closing and reopening your template. You will be greeted by something like this.

The solution to this problem is to add an Encoding attribute to the CodeTemplate directive before saving.

<%@ CodeTemplate Language="C#" TargetLanguage="C#" Encoding="UTF-8" %>

Posted Oct 23 2008, 05:26 AM by Blake Niemyjski |
Filed under: , ,;
Copyright © 2008 Windows Coding
Microsoft and Microsoft logo's are trademarks of Microsoft Corporation.