{"id":3126,"date":"2010-08-17T20:45:00","date_gmt":"2010-08-17T20:45:00","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/modifying-built-in-visual-studio-project-templates\/"},"modified":"2016-07-28T10:50:07","modified_gmt":"2016-07-28T10:50:07","slug":"modifying-built-in-visual-studio-project-templates","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/modifying-built-in-visual-studio-project-templates\/","title":{"rendered":"Modifying built-in Visual Studio project templates"},"content":{"rendered":"<p>As some of you may know, executable projects created in Visual Studio 2010 now <a href=\"http:\/\/blogs.msdn.com\/b\/rmbyers\/archive\/2009\/06\/08\/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx\">default to the x86 build target<\/a> 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.<\/p>\n<p><b>Modifying built-in templates<\/b><\/p>\n<p>All the project templates in the Visual Studio &#8216;New Project&#8217; screen are stored in zip files on disk; on my computer, these are located at <code>C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEProjectTemplates<\/code>. The templates themselves are in subfolders; the &#8216;Windows Forms Application&#8217; and &#8216;Console Application&#8217; templates I wanted to edit were in the <code>CSharpWindows1033<\/code> subdirectory.<\/p>\n<p>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&#8217;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.<\/p>\n<p><b>x86 -&gt; AnyCPU<\/b><\/p>\n<p>To change the default target from x86 to AnyCPU, edit the .csproj file and change references from &#8216;x86&#8217; to &#8216;AnyCPU&#8217; &#8211; there should be a <code>Platform<\/code> xml element, two <code>PropertyGroup<\/code> conditions, and two <code>PlatformTarget<\/code> elements (these can be removed completely).<\/p>\n<p>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 <code>System.dll<\/code> from the assembly references, and removed the <code>Class1.cs<\/code> file from the Class Library template (note that if you&#8217;re removing files you&#8217;ll have to remove references from the .vstemplate file as well as the .csproj file).<\/p>\n<p><b>Re-creating the template cache<\/b><\/p>\n<p>Once you&#8217;ve made all the changes you want, and overwritten the zip files with the new copies, you need to delete the contents of the <code>Common7IDEProjectTemplatesCache<\/code> directory, and run <code>devenv \/installvstemplates<\/code> 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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;&hellip;<\/p>\n","protected":false},"author":186659,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"coauthors":[],"class_list":["post-3126","post","type-post","status-publish","format-standard","hentry","category-blogs"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/186659"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=3126"}],"version-history":[{"count":1,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3126\/revisions"}],"predecessor-version":[{"id":25093,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3126\/revisions\/25093"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=3126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=3126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=3126"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=3126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}