简体   繁体   English

Visual Studio 2012不生成命名空间

[英]Visual Studio 2012 Not Generating Namespaces

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 我的团队最近将一个ASP.NET网站项目从VS 2010迁移到2012年。在2010年创建新页面和代码隐藏文件时,将使用基于文件创建结构的文件夹创建一个名称空间来创建该文件。例如,在MyProject中创建一个名为MyPage.aspx.cs的文件 - > Folder1 - > Folder2将生成一个看起来像

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 在2012年,创建的文件没有命名空间,文件夹结构附加到带有下划线的类名称

public partial class MyProject_Folder1_Folder2_MyPage
{

}

We prefer the look of the 2010 style as it seems much cleaner to us. 我们更喜欢2010款式的外观,因为它对我们来说似乎更清洁。 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. 这似乎应该是一个简单的设置,但我找不到任何关于这个问题的文档。

This is happening because the project is configured as a Web Site instead of a Web Application . 发生这种情况是因为项目被配置为Web Site而不是Web Application Try converting the to a web application and see if that addresses the behavior in question. 尝试将其转换为Web应用程序,看看是否可以解决相关行为。

Regarding Web Site projects, MSDN states the following: 关于Web Site项目,MSDN声明如下:

Explicit namespaces are not added to pages, controls, and classes by default, but you can add them manually. 默认情况下,显式命名空间不会添加到页面,控件和类中,但您可以手动添加它们。

Check out these link for details: 查看这些链接了解详情:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM