从 VS 2010 发布 Web 应用程序后出现问题
每当我通过一键发布功能在 VS 2010 中发布我的 MVC Web 应用程序时(我还没有进行任何 web.config 转换或任何奇特的操作!)。下次我来构建应用程序时,我收到以下错误:
使用注册为allowDefinition='MachineToApplication'的部分是错误的 超出应用程序级别。此错误可能是由于虚拟目录未创建而导致的 配置为 IIS 中的应用程序。在 ...MyWebApp\obj\release\package\packagetmp 中 \web.config
VS2010 确实在 ...MyWebApp\obj\ 文件夹下创建了 web.config 文件的新副本,因此我删除了整个 obj 文件夹,然后能够再次构建。
但我不必每次发布时都这样做 - 我必须有一些配置不正确 - 任何人都可以帮忙。
谢谢。
Whenever I publish my MVC web application in VS 2010 via the One-click publish feature (I'm not doing any web.config transforms or anything fancy - yet!). The next time I come to build the app I get the following error:
It is an error to use a section registered as allowDefinition='MachineToApplication'
beyond application level. This error can be caused by a virtual directory not being
configured as an application in IIS. in ...MyWebApp\obj\release\package\packagetmp
\web.config
A new copy of the web.config file is indeed created by VS2010 below the ...MyWebApp\obj\ folder so I deleted the whole obj folder and I was then able to build again.
But I shouldn't have to do that each time I publish - I must have something configured incorrectly - can anyone help please.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,这是将 Web 应用程序发布到文件系统的一个已知问题。这仍然会影响 Visual Studio 2010 的发布版本 (RTM)。它不限于 Beta 或 RC 版本。
这个问题也“困扰”了我,我也必须手动删除网站内
obj
文件夹内的Debug
和Release
文件夹解决方案文件夹。自动“解决方法”的真正答案可以在 此答案对另一个 Stack Overflow 问题:
为什么在构建 MVC 项目时会随机出现“使用注册为allowDefinition='MachineToApplication'的节时出错”?
简而言之,您需要从
Debug
或Release
文件夹(或两者!)中删除web.config
文件,这就是使用预构建命令实现(在解决方案的Project Properties
页面的Build Events
选项卡中配置):就个人而言,我删除整个
obj 文件夹,因为无论如何,所有这些文件都会在每次构建时重新创建。
This is unfortunately a known issue with Publishing a web application to the file system. This still affects the release version (RTM) of Visual Studio 2010. It's not limited to the Beta or RC versions.
This problem "bit" me also, and I too was having to manually delete the
Debug
andRelease
folders inside theobj
folder within my web site solution folder.The real answer for an automated "workaround" can be found in this answer to the other Stack Overflow question:
Why do I randomly get a “error to use section registered as allowDefinition='MachineToApplication'” when building an MVC project?
In a nutshell, you need to delete the
web.config
files from either theDebug
orRelease
folders (or both!), and that's achieved with a pre-build command (configured in theBuild Events
tab of theProject Properties
page of your solution):Personally, I delete the entire
obj
folder since all those files are re-created with each build anyway.我刚刚找到了一个对我有用的解决方法,打开您的 Web 项目的 .csproj 并将 Project\PropertyGroup 节点下的节点更改为:
从此:
true
对此:
假
这对我有用,希望对你也有用。
I have just found a work around for this that has worked for me, open the .csproj for your web project and change the node under the Project\PropertyGroup node to this:
from this:
<MvcBuildViews>true</MvcBuildViews>
to this:
<MvcBuildViews>false</MvcBuildViews>
This has worked for me, hopefully it will work for you also.