VS2008, Item Templates and Unicode files to ANSI

I’ve just created a load of text files with Visual Studio 2008, only to discover they’re:

Unicode (UTF-8 with signature) – Codepage 65001

Very annoying because I wanted ANSI files, and they get marked as binary in Subversion (well, actually they get automatically tagged with the svn:mime-type “application/octet-stream”).

The cause of this is that the item templates for TextFile in Visual Studio have the Unicode byte marks.

The solution is to knobble them in your copy of visual studio:

Go to

%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates

and search for TextFile.zip.

On x64 they’re here:

%ProgramFiles(x86)%\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates

Anyway, depending on your edition of Visual Studio and your installation choices, you may find several of these. In each case, you need to overwrite the two-byte or three-byte TextFile.txt in the zip file with a zero-byte version.

You’ll also want to similarly knobble any other TextFile.txt you can find in your Visual Studio directory – there are several in mine which are used to create files when not inside a particular project type.

Once you’ve sorted all this out, you need Visual Studio to refresh template cache:

 

x86: "%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\devenv.com" /setup

x64: "%ProgramFiles(x86)%\Microsoft Visual Studio 9.0\Common7\IDE\devenv.com" /setup

 

So, what do you do if you have just created dozens of Unicode files which you now rather wish were ANSI?

Well, my answer in powershell 1.0 is as follows:

Get-ChildItem -recurse -filter "*.sol" | foreach { $_.Name | Out-Default; ( Get-Content $_.PSPath ) | Set-Content $_.PSPath }

Obviously my files all ended in the .sol extension and were spread around a whole directory tree – you can change the options for Get-ChildItem to suit your purposes.

And finally, because for some reason (I think TortoiseSVN had already added the svn:mime-type “application/octet-stream” properties):

svn propdel –recursive –quiet svn:mime-type .\*

And that’s all for now, folks!

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s