locked
Custom File Type + C# Editor + Extra stuff! RRS feed

  • Question

  • Hi,

    I wish to support a new file type (.csh), but also still be able to edit it with the C# editor. I achieved this by goint to Tools>Options>Text Editor>FileExtensions and adding my custom extension and linking it to the C# editor.

     

    Now though I'd like to have more control over it. Specifically when the user creates a .csh file, instead of seeing this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Boiler_Plate
    {
    	class Class1
    	{
    	}
    }
    
    

    I'd like it to be something else I specify. Is it possible to write this with a macro or a visual studio extension?

     

     

    Next I'd also like to be able to, when the user builds the project, create a new file based on information in the .csh file. Is it possible to hook on to build events and do that? To add a file to the solution.

     

    I am using Visual Studio 2010.

     

    Saturday, January 14, 2012 10:25 PM

Answers

  • Hi Alex,

    You'll need to elaborate a bit more concerning what you mean by "I'd like this to be something else I specify". All you've done at this point is tell the C# project system to treat your .CSH file as it it were a .CS file. If you are looking to build your own designer around that .CSH file, you'll need to implement a custom editor (meaning a VSPackage using the Visual Studio SDK).

    Depending upon your specific requirements, regarding build. You should have a look at implementing a SingleFileGenerator. A single file generator is a tool associated with a specific file type that will generate output (typically code) that can be included directly back into your project's build.

    Sincerely,


    Ed Dore
    Tuesday, January 17, 2012 3:28 AM

All replies

  • Hi Alex_hbg,

    According to your description, I think what you need is to create an Item Template,

    You can add your own code to your Item Template, please refer to the following link to learn how to create an Item Template.

    How to: Manually Create Item Templates:

    http://msdn.microsoft.com/en-us/library/ms247113.aspx

    How to: Create Item Templates

    http://msdn.microsoft.com/en-us/library/tsyyf0yh.aspx

    Please mark the useful reply as answer.

     

    Best regards,

    Lucy


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us
    Monday, January 16, 2012 9:19 AM
  • Hi Alex,

    You'll need to elaborate a bit more concerning what you mean by "I'd like this to be something else I specify". All you've done at this point is tell the C# project system to treat your .CSH file as it it were a .CS file. If you are looking to build your own designer around that .CSH file, you'll need to implement a custom editor (meaning a VSPackage using the Visual Studio SDK).

    Depending upon your specific requirements, regarding build. You should have a look at implementing a SingleFileGenerator. A single file generator is a tool associated with a specific file type that will generate output (typically code) that can be included directly back into your project's build.

    Sincerely,


    Ed Dore
    Tuesday, January 17, 2012 3:28 AM