Reputation: 196459
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?
Upvotes: 4
Views: 2549
Reputation: 5932
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">
<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.
Upvotes: 4
Reputation: 7154
try to run devenv /resetsettings
it has to be run from the Visual Studio command prompt
Upvotes: 0
Reputation: 1405
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.
Upvotes: 11
Reputation:
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?
Upvotes: 1
Reputation: 101
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.
Upvotes: 2