As some of you may know, executable projects created in Visual Studio 2010 now default to the x86 build target rather than AnyCPU, as was the case in VS2008. I personally am quite annoyed by this decision, and so I looked for ways to change it back. A poke through the VS options screen proved fruitless, however I was able to modify the Visual Studio templates themselves to affect this change. This post explains how to do it.
Modifying built-in templates
All the project templates in the Visual Studio ‘New Project’ screen are stored in zip files on disk; on my computer, these are located at
C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEProjectTemplates. The templates themselves are in subfolders; the ‘Windows Forms Application’ and ‘Console Application’ templates I wanted to edit were in the
Editing these are fairly simple, as they have the same structure as user project templates. All the needed .csproj and .cs files are included in the zip, along with a .vstemplate file that tells Visual Studio what to do with each file. To edit these files you’ll need to extract the zip, edit the files, and then remove/rename the old zip file and replace it with a new zip file containing the edited files.
x86 -> AnyCPU
To change the default target from x86 to AnyCPU, edit the .csproj file and change references from ‘x86’ to ‘AnyCPU’ – there should be a
Platform xml element, two
PropertyGroup conditions, and two
PlatformTarget elements (these can be removed completely).
You can also make any other changes you wish; as well as changing the console and windows forms project targets back to AnyCPU, I removed everything but
System.dll from the assembly references, and removed the
Class1.cs file from the Class Library template (note that if you’re removing files you’ll have to remove references from the .vstemplate file as well as the .csproj file).
Re-creating the template cache
Once you’ve made all the changes you want, and overwritten the zip files with the new copies, you need to delete the contents of the
Common7IDEProjectTemplatesCache directory, and run
devenv /installvstemplates in a Visual Studio command prompt, which will re-create the cached templates using your versions. The new templates will then be used for any subsequent created projects.