1

My team recently moved an ASP.NET website project from VS 2010 to 2012. When creating a new page and code behind file in 2010, the file would be created with a namespace based on the folder the structure the file was created in. For example, a file named MyPage.aspx.cs created in MyProject -> Folder1 -> Folder2 would be generated looking like

namespace MyProject.Folder1.Folder2
{
    public partial class MyPage
    {

    }
}

In 2012, the same file is created without a namespace, and the folder structure is appended to the class name with underscores like

public partial class MyProject_Folder1_Folder2_MyPage
{

}

We prefer the look of the 2010 style as it seems much cleaner to us. How can we get new files to generate with namespaces in that manner? This seems like it should be a simple setting somewhere, but I cannot find any documentation on the issue.

4

1 回答 1

3

发生这种情况是因为项目配置为 aWeb Site而不是Web Application. 尝试将其转换为 Web 应用程序,看看是否能解决相关问题。

关于Web Site项目,MSDN 声明如下:

默认情况下,显式命名空间不会添加到页面、控件和类中,但您可以手动添加它们。

查看这些链接了解详情:

于 2013-10-15T15:04:27.503 回答