Вопрос

I've got a web app project that I'm looking at creating some item templates for in VS 2010, any new pages created from these templates need to have a using statement for my mainClasses folder. The problem is that every time a new page is created VS changes the using statement from using MyProject.mainClasses to MyProject.LocationOfPage.mainClasses. It is obviously looking for the project name so it can change the namespace accordingly but annoyingly its also changing my using statement, which breaks my project.

I think this would't be a problem if I had a website project and an App_Code folder as I wouldn't need a using statement but it's not and I can't so I'm stuck :(

Any help greatfully appreciated if anyone can figure out what I'm bumbling on about.

Cheers

Russ

PS I'm using C#.

Это было полезно?

Решение

You can edit the file in the template to remove the placeholder. The itemtemplate us just a zipfile with the necessary files in it. In each file the project or namespacename will be replaced on projectcreation.

Look for placeholders like '$safeprojectname$'

Другие советы

I'd suggest adding your namespaces to your Web.Config file rather than using a custom template if all you need are using statements.


<namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    <add namespace="StackExchange.Profiling"/>
    <add namespace="MyProject.mainClasses"/>
    <add namespace="Some.Other.Namespace"/>
    <add namespace="One.More.Namespace"/>
</namespaces>

This will make those namespaces available in all of your pages without referencing them explicitly.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top