无法将 App_Code 文件夹添加到网站项目
使用 VS2008,我尝试从 add-->folder-->Add ASP_NET 文件夹添加 App_Code 文件夹。
App_Code 文件夹选项按预期存在,但是...它被禁用了!?
我很确定我正在使用一个网站项目(而不是一个 Web 应用程序),因为我可以添加所有其他 ASP_NET 文件夹(App_Data - App_themes 等),而且因为我的代码后面没有控件声明(与 Web 应用程序相反,Web 应用程序具有带有控件声明和事件处理程序等的部分类)。 事实是,如果它不是网站项目,我怎么可以添加其他 ASP_NET 文件夹? 而且 - 为什么我没有得到任何带有控件声明等的设计器文件? 这就是 VS2005 中过去的工作方式。
如果我继续自己添加 App_Code 文件夹作为普通文件夹,它会拾取 ASP_NET App_Code 文件夹的图标 - 所以它似乎工作正常。
但它仍然困扰着我,因为我不明白为什么该选项首先被禁用。
知道为什么会发生这种情况吗?
编辑:我正在尝试创建一个新的网站,但我只得到网络应用程序模板,所以我怀疑我是否能够创建一个网站首先。 这里有点困惑!
Using VS2008, I am trying to add an App_Code folder from add-->folder-->Add ASP_NET folder.
The App_Code folder option is there as expected BUT ... it's disabled!?
I am pretty sure I am working with a WebSite project (and not a Web Application) because I can add all the other ASP_NET folders (App_Data - App_themes etc) and also because I don't have the controls declarations in my-code behind (as opposed to Web Application where you have partial classes with controls declaration and eventHandlers etc.). Fact is, if it's not a website project how come I can add the other ASP_NET folders? And also - why I am not getting any designer file with controls declaration etc? This is the way things used to work in VS2005.
If I go ahead and add App_Code folder myself as a normal folder it picks-up the icon of the ASP_NET App_Code folder - so it seems to be working fine.
Still it's bugging me 'cause I can't understand why the opion is disabled in the first place.
Any clue why this is happening?
EDIT: I am trying to create a new web site and I get only the web application template so I doubt I was able to create a website in the first place. A bit confused here!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
不知道为什么会发生这种情况,但您应该能够在解决方案资源管理器中添加一个新文件夹并将其重命名/称为 App_Code。
如果您愿意,甚至可以在 Windows 资源管理器中执行此操作。
刷新一下,它就会拾取它。
No idea why it's happening, but you should be able to just add a new folder in the Solution Explorer and rename/call it App_Code.
Do this in Windows Explorer even, if you like.
Refresh and it'll pick it up.
您确定这是网站项目而不是网络应用程序?
Are you sure it is web site project and not web application?
您向项目添加一个新文件夹。 然后,将其重命名为 App_Code。 Visual Studio可以将该文件夹修改为App_Code文件夹。
You add a new folder to project. Then, rename it as App_Code. Visual studio could revise the folder as App_Code folder.
可能如果您添加 .cs 文件,它就会被创建吗?
这个选项以前对您有用吗? 在它停止工作之前您是否做了什么?
May be if you add .cs file, it will be created?
Did this option worked for you before? Did you do something before it stopped working?
确实不存在“网站项目”这样的东西。 网站是无项目的,因为它们的文件夹中不包含 .csproj(或 .vbproj)文件。 如果您看到此文件,那么它是一个“Web 应用程序”项目。 另外,如果您从菜单中选择“新项目...”,那么您就没有选择“网站”。
使用网站的唯一方法是从 VS 文件菜单中选择“新网站”。
There's really no such thing as a "web site project". Web sites are project-less, in that they don't contain a .csproj (or .vbproj) file in the folder. If you see this file, then it's a "web application" project. Also, if you're selecting from the menu "new project...", then you're not selecting a "web site".
The only way that you're using a web site, is by selecting "new web site" from the VS File menu.
如果您正在网站而不是 Web 应用程序中工作,则只能访问“新建 ASP.Net 文件夹”下拉列表中的
App_Code
新文件夹选项。 也把我抓出来过几次。 希望这有帮助。You can only get to the
App_Code
new folder option in the New ASP.Net Folder drop down if you are working in a Website and not in a web application. Caught me out a few times too. Hope that this helps.您无法将 App_Code 文件夹添加到 Web 应用程序,因为该文件夹是为 asp.net 运行时编译而设计的,而 Web 应用程序项目是为您将网站预编译为 dll 而设计的,您可以在 Bin 文件夹中找到该 dll 并进行部署到您的网站。
因此,对于 Web 应用程序项目,您应该添加一个名为“CodeFolder”之类的文件夹,然后在其中添加您的类。 然后右键单击该类文件的属性并将其构建配置设置为编译而不是内容。
you can't add the App_Code folder to a Web Application because this folder is designed for runtime compilation by asp.net and the Web Application project is designed for you to precompile your website into a dll which you can find in the Bin folder and deploy to your site.
So, for Web App Projects, you should instead Add a folder called something like 'CodeFolder' and then add you class in there. Then right click properties on that class file and set its build config to compile rather than content.