allowDefinition=“MachineToApplication”从 VS2010 发布时出错(但仅在之前的构建之后)
我可以在本地计算机上毫无问题地运行我的 Asp.Net MVC 2 应用程序。只需运行/调试。
但如果我已经构建了它,我就无法发布它!我必须清理解决方案并再次发布。我知道这不是系统关键,但这确实很烦人。 “一键发布”不是“清理解决方案然后一键发布”
具体错误如下:
错误11 使用a是错误的 部分注册为 允许定义='机器到应用程序' 超出应用程序级别。这个错误 可能是虚拟目录引起的 未配置为应用程序 在 IIS 中。
我怀疑这与 Views 文件夹中的 Web.Config 有关,但为什么只有在我之前构建过一次之后。需要注意的是,该应用程序一旦发布就可以正常工作。
I can run my Asp.Net MVC 2 application without an issue on my local computer. Just Run / Debug.
But if I have already built it, I can't publish it! I have to clean the solution and publish it again. I know this is not system critical, but it's really annoying. "One Click Publish" is not "Clean solution and then One click publish"
The exact error is as follows:
Error 11 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.
I suspect it's something to do with the Web.Config in the Views folder, but then why only after I build once previously. And just to note, the app works fine once published.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
我的 MVC 应用程序也有同样的问题。这很令人沮丧,因为我仍然希望检查我的视图,所以我不想关闭 MvcBuildViews
幸运的是我遇到了 帖子 这给了我答案。将 MvcBuildViews 保持为 true,然后您可以在项目文件下面添加以下行:
并使该文件夹不在您的项目文件夹中。对我有用。这不是一个完美的解决方案,但目前来说是好的。确保从项目文件夹中删除 package 文件夹(位于 obj\Debug 和/或 obj\Release 文件夹内),否则您会会不断收到错误。
FWIW,MS了解此错误...
i had the same problem with my MVC apps. it was frustrating because i still wanted my views to be checked, so i didn't want to turn off MvcBuildViews
luckily i came across a post which gave me the answer. keep the MvcBuildViews as true, then you can add the following line underneath in your project file:
And make that folder not in your project's folder. Works for me. It's not a perfect solution, but it's good for the moment. Make sure you remove the package folder (located inside the obj\Debug and/or obj\Release folder) from your project folder otherwise you'll keep getting the error.
FWIW, MS know about this error...
我删除了 obj/Debug 文件夹中的所有内容,并修复了此错误。这允许我保留
项目文件中的选项(这与 T4MVC T4 模板一起派上用场)。
编辑:
只需使用“Build”->“Build”即可轻松实现这一点。 “重建解决方案”菜单(因为重建实际上所做的是清除 obj/Debug 文件夹,然后构建解决方案)。
I deleted everything out of my obj/Debug folder and it fixed this error. This allowed me to leave in the
option in my project file (which comes in handy with the T4MVC T4 template).
Edit:
This can be achieved much easier by simply using the "Build" -> "Rebuild Solution" menu (because what rebuild actually does is clear the obj/Debug folder and then build solution).
我在 MS Connect 页面查看此错误。在运行 AspNetCompiler 之前,它会清除项目下的所有 obj 和临时文件(所有配置)。
I'm using this workaround on the MS Connect page for this error. It cleans all obj and temp files under your project (all configurations) before running AspNetCompiler.
当 obj 文件夹中存在 Web 项目输出(模板化 web.config 或临时发布文件)时,会出现此问题。使用的 ASP.NET 编译器不够智能,无法忽略 obj 文件夹中的内容,因此它会抛出错误。
另一个修复方法是在调用之前取消发布输出。打开 .csproj 并将其更改
为
:这将删除 \obj 下的所有 web.config,以及 \obj 下的所有 PackageTmp 文件夹。
This problem occurs when there is web project output (templated web.config or temporary publish files) in the obj folder. The ASP.NET compiler used isn't smart enough to ignore stuff in the obj folder, so it throws errors instead.
Another fix is to nuke the publish output right before calling <AspNetCompiler>. Open your .csproj and change this:
to this:
That will delete all web.configs under \obj, as well as all PackageTmp folders under \obj.
如果您使用的是 Web Publish,则可以设置
MvcBuildViews=false
和PrecompileBeforePublish=true
,这会在复制到临时文件夹后(紧接着发布/打包之前)进行预编译。注意:
PrecompileBeforePublish
仅受“新”Web 发布管道堆栈(VS2010 SP1 + Azure SDK 或 VS2012 RTM)支持。如果您使用的是 VS2010 RTM,则需要使用其中一种替代方法。If you are using Web Publish, you can set
MvcBuildViews=false
andPrecompileBeforePublish=true
, which precompiles after the copy to the temporary folder (immediately before publish/package).NOTE:
PrecompileBeforePublish
is only supported by the "new" Web Publishing Pipeline stack (VS2010 SP1 + Azure SDK or VS2012 RTM). If you're using VS2010 RTM, you'll need use one of the alternative methods.关于jrummell的解决方案,设置:
DependsOnTargets =“CleanWebsitesPackage;CleanWebsitesPackageTempDir;CleanWebsitesTransformParametersFiles;”
它可以在 VS 2010 中运行,但不能在 VS 2012 中运行。 2012 年你必须输入:
DependsOnTargets =“CleanWebsitesPackage;CleanWebsitesWPPAllFilesInSingleFolder;CleanWebPublishPipelineIntermediateOutput”
来源
:
VS 2010:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets
VS 2012:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets
Regarding the solution by jrummell, the setting:
DependsOnTargets="CleanWebsitesPackage;CleanWebsitesPackageTempDir;CleanWebsitesTransformParametersFiles;"
It works in VS 2010, but not in VS 2012. In 2012 you have to put:
DependsOnTargets="CleanWebsitesPackage;CleanWebsitesWPPAllFilesInSingleFolder;CleanWebPublishPipelineIntermediateOutput"
Source:
VS 2010:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets
VS 2012:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets
我知道这个问题已经得到解答,但我只是想添加一些我发现的有趣的东西。
我已在项目中将“MvcBuildViews”设置为 false,删除了所有 bin 和 obj 文件夹,但仍然收到错误。我发现有一个“.csproj.user”文件仍然将“MvcBuildViews”设置为 true。
我删除了“.csproj.user”文件,然后一切正常。
因此,如果您要更改 csproj 文件,请确保同时更改或删除“.csproj.user”文件。
I know this has been answered but I just wanted to add something interesting I found.
I had set the "MvcBuildViews" to false in the project, deleted all bin and obj folders and I was still getting the error. I found that there was a ".csproj.user" file that still had "MvcBuildViews" set to true.
I deleted the ".csproj.user" file and then it all worked.
So make sure if you are changing your csproj file that you either change or delete the ".csproj.user" file also.
我也遇到了这个问题,所以我在项目属性中创建了一个预构建事件来清理输出目录(
${projectPath}\bin,${projectPath}\obj\${ConfigurationName}
)。在另一个项目中,即使进行了清洁活动,我也遇到了这个错误。在第二个项目中,我正在编译项目文件中列出的视图:我将 true 更改为 false,并且它不再抱怨该错误,但仍然正确运行。我不会声称我确切知道是什么导致了第二个错误,但至少它暂时让我继续前进。
I had this problem as well, so I created a Pre-Build Event in the project properties to Clean the output directories(
${projectPath}\bin,${projectPath}\obj\${ConfigurationName}
). On another project I was also getting this error, even with the cleaning event in place. On the second project I was compiling the views as listed in the project file:I changed the true to false, and it no longer complained about that error, but still ran correctly. I won't claim I know exactly what was causing the second error, but at least it got me moving forward for the time being.
该问题与中间文件有关,但还有另一种解决方案,即在构建视图之前清理这些中间文件。
这个解决方案已经包含在VS的某些版本中,但我只能说我在VS 2013 Update 5中遇到了这个问题。(参见下面的“注意”,它可以在这个版本中修复,但仅在我的特定非标准情况下不起作用)。
我从 错误:allowDefinition= 借用了解决方案Visual Studio Connect 上的“MachineToApplication”超出了应用程序级别。
解决方案包括将这些行包含到 Web 应用程序项目(
.csproj
文件)中,以处理删除问题的中间文件:< strong>注意:由于某种原因,可能是因为我自己将其包含在项目中,我用于构建视图的构建目标被命名为
"BuildViews"
,而不是"MvcBuildViews"
,所以我必须相应地修改BeforeTargets
属性。我还通过删除PropertyGroup
并简化条件来简化目标,如下所示:The problem has to do with the intermediate files, but there is another solution which consist in cleaning up those intermediate files before builnding the views.
This solution has been included in some version of VS, but I can only say that I had the problem in VS 2013 Update 5. (See the "Beware" below, it could be fixed in this version, but not working only in my particular non-standard case).
I borrowed the soltuion from Error: allowDefinition='MachineToApplication' beyond application level on Visual Studio Connect.
The solution consist in including these lines to the web application project (
.csproj
file) which handle the deletion of the offedning intermediate files:Beware: for some reason, probably because I included it myself in the project, my build target for building the views was named
"BuildViews"
, instead of"MvcBuildViews"
, so I had to modify theBeforeTargets
attribute accordingly. I also simplified the target, by removing thePropertyGroup
and simplifying the condition, like this:就我而言,我发现当我将 MvcBuildViews 和 PrecompileDuringPublish 都设置为 true 时,这就是导致此问题的原因。
所以我删除了 PrecompileDuringPublish,该解决方案对我有用,从那以后我就没有遇到过这个问题。
In my case i saw that when i have MvcBuildViews and PrecompileDuringPublish as both true - was what was causing this issue.
So i removed the PrecompileDuringPublish and that solution worked for me and i have not faced this problem since.