[英]How to stop Visual Studio Web writing web.config to /obj directory
I'm using MSDeploy (Web Deploy) to publish my MVC application, which works great. 我正在使用MSDeploy(Web部署)发布我的MVC应用程序,效果很好。 The only issue is that it puts all the compiled files, along with an extra web.config in the obj directory, so the next time I try to build I get the following error:
唯一的问题是,它将所有已编译的文件以及一个额外的web.config放在obj目录中,因此,下次我尝试构建时,出现以下错误:
Error 1 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.
If I delete obj the problem goes away, but it is annoying. 如果我删除obj,问题就消失了,但这很烦人。 I could put a post-build task to do this for me, but it feels wrong.
我可以提出一个构建后任务来为我完成此任务,但这感觉不对。 Shouldn't there be a better way?
不应该有更好的方法吗?
I assume that you're using MvcBuildViews to compile your site during a build in Visual Studio, as the default behavior for precompile during publish is to copy site contents to a temp folder and precompile that folder (so as to avoid issues like obj
or other excluded files). 我假设您在Visual Studio的构建过程中使用MvcBuildViews来编译您的网站,因为发布期间预编译的默认行为是将网站内容复制到temp文件夹并预编译该文件夹(以避免
obj
或其他问题排除的文件)。
The easiest workaround, documented here , is to relocate your obj
directory elsewhere, like this: 这里记录的最简单的解决方法是将
obj
目录重新定位到其他位置,如下所示:
<BaseIntermediateOutputPath>Somewhere\Not\Under\Project\Directory</BaseIntermediateOutputPath>
Longer explanation: 更长的解释:
MvcBuildViews invokes the ASP.NET compiler as such in the project file: MvcBuildViews会在项目文件中这样调用ASP.NET编译器:
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
The complier by default will compile all contents of the site below that root folder specified. 默认情况下,编译器将编译该根目录下的站点的所有内容。 The error stems from when
obj\\web.config
contains things that are only allowed in the site root web.config
(since that's where it was copied from). 该错误源于
obj\\web.config
包含仅在站点根目录web.config
允许的内容(因为它是从那里复制的)。
2 other workarounds: 2种其他解决方法:
I had my web.config property "Copy To Output Directory" set to "Copy Always". 我将我的web.config属性“复制到输出目录”设置为“始终复制”。 Setting it back to "Do not copy" resolved it for me.
将其重新设置为“请勿复制”为我解决了该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.