views:

446

answers:

7

I upgraded to Visual Studio 2008 and for some reason when I create new class files, it loads a completely blank file as opposed to giving me the basic using code and the list of the class name (being the file name).

So if I create a new code file called Order.cs, it is no longer put in by default:

using system;

public class Order
{
}

Is this a Visual Studio user preference?

A: 

It could be possible that your default language has not been set.

This link should help you change the default language to c# (which I am assuming from your question is the language you are going to use in Visual Studio).

Davie
nope. this didn't seem to help at all.
ooo
+2  A: 

Check you have the following file on your system.
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip

If not check out this Blog Post which has a brief explaination on running devenv /installvstemplates or google with bing

devenv /installvstemplates

I once had a similiar issue when I had visual webdeveloper installed and then upgraded to full visual studio pro.

If the files are in fact there I am sorry I have not had that issue and you might want to search T4 templates as I think this is what Visual Studio uses to take the template file and make it your new class file complete with class name etc.

ozdeveloper
hmm. i have C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\class.zip and i opened it up in notepad and it looks correct but doesn't seem to apply when i click "New -> Code"
ooo
ozdeveloper
yes vs 2008 sp1
ooo
'google with bing'. love it.
Sam Holder
A: 

try on the vs command prompt:

devenv.exe /installvstemplates
eglasius
its not recognizing this command
ooo
@oo oops, messed it up when writing - updated. Make sure to run it from the vs command prompt.
eglasius
@oo did u try this after my change?
eglasius
+1  A: 

Just to cover all bases...

The template for "Code File" is blank and the template for "Class" has what you expect.

Are you sure you're selecting the template for Class and not Code File?

Will
+11  A: 

You mentioned in the comments you were pressing "New->Code", dont, thats supposed to be blank. click Add>NewItem>Class , Make sure its a "Class" you select not just a code file.

Fusspawn
A: 

try to run devenv /resetsettings it has to be run from the Visual Studio command prompt

mfeingold
+3  A: 

If you ARE using Add -> Class OR Add -> New Item and then selecting Class, and you're still only getting an empty code file, then your default "class" template is missing or messed up. If you are using Add -> Code OR Add -> New Item and selecting Code, the "Code" template is simply an empty ".cs" file, and will be given to you empty as such.

In C# Express, this file should be located at "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\VCSExpress\ItemTemplates\1033\". The template for the full (paid) version of Visual Studio will be the exact same file, only the folder location will differ. The file should be a standard zip file named "Class.zip". This zip file should contain two files, as follows:

First file should be named "Class.cs" and contain:

using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ == 3.5)using System.Linq;
$endif$using System.Text;

namespace $rootnamespace$
{
    class $safeitemrootname$
    {
    }
}

Second file should be named "Class.vstemplate" and contain:

<?xml version="1.0" encoding="utf-8"?>
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"&gt;
  <TemplateData>
    <Name Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="2245" />
    <Description Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="2262" />
    <Icon Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="4515" />
    <TemplateID>Microsoft.CSharp.Class</TemplateID>
    <ProjectType>CSharp</ProjectType>
    <RequiredFrameworkVersion>2.0</RequiredFrameworkVersion>
    <NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
    <DefaultName>Class.cs</DefaultName>
  </TemplateData>
  <TemplateContent>
     <References>
      <Reference>
       <Assembly>System</Assembly>
      </Reference>
      <Reference>
       <Assembly>System.Data</Assembly>
      </Reference>
      <Reference>
       <Assembly>System.Xml</Assembly>
      </Reference>
     </References>

    <ProjectItem ReplaceParameters="true">Class.cs</ProjectItem>
  </TemplateContent>
</VSTemplate>

If you put all of this in place, and you still get a blank code file, consider reinstalling Visual Studio.

md5sum
+1 for the location. VCSExpress also has an ItemTemplates folder in the IDE folder, but this appears to be a red herring! As you state in your answer, \IDE\VCSExpress\ItemTemplates is the folder to go for!
Tim Gradwell