Error: allowDefinition='MachineToApplication' beyond application level - by Trips2007

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 779737 Comments
Status Closed Workarounds
Type Bug Repros 14
Opened 2/21/2013 12:26:02 PM
Access Restriction Public


I experienced the error shortly after configuring and using the Publishing Wizard in Visual Studio 2012:

Error 20 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.	

Note that many users have experienced this in both VS2010 and VS2012.  It is terribly inconvenient to work around the issue because it sometimes requires the `bin` and `obj` folders to be manually deleted *for every single compile* once the bug begins to manifest.  Even if that were automated as a build task (for every project...), that greatly increases compile time for large solutions.

Coverage on StackOverflow:
Sign in to post a comment.
Posted by Jonathan 1234 on 8/7/2015 at 1:43 PM
I have seen the correction in microsoft.web.publishing.targets But it is missing another temp folder: AspnetCompileMerge

It should be:

<!--Deal with,
we will need to clean up our temp folder before MVC project starts the pre-compile-->
    <_EnableCleanOnBuildForMvcViews Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='' ">true</_EnableCleanOnBuildForMvcViews>
<Target Name="CleanupForBuildMvcViews" Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='true' and '$(MVCBuildViews)'=='true' " BeforeTargets="MvcBuildViews">
     <_PublishTempFolderNamesToCleanup Include="Database;TransformWebConfig;CSAutoParameterize;InsertAdditionalCS;ProfileTransformWebConfig;Package;AspnetCompileMerge" />
    <!--Force msbuild to expand all the wildcard characters so to get real file paths-->
    <CreateItem Include="@(_PublishTempFolderNamesToCleanup->'$(BaseIntermediateOutputPath)**\%(identity)\**\*')">
     <Output TaskParameter="Include" ItemName="_EvaluatedPublishTempFolderNamesToCleanup" />
    <Delete Files="@(_EvaluatedPublishTempFolderNamesToCleanup)" />

Could you update the section in a future release?


Posted by fabian valencia on 8/7/2014 at 11:15 AM
I'm having the same issue running Visual Studio 2012, the MvcBuildViews is set to false for me, and the workaround doesn't work for me either.

Posted by Yugang [MSFT] on 11/12/2013 at 11:38 AM
We will fix it in a future release of "ASP.NET Web Framework and Tools"
         Microsoft Visual Web Developer team
Posted by Sayed [MSFT] on 7/16/2013 at 2:19 PM
Sorry for the delay here. Here is an explanation of what is happening here as well as a work around.

When publishing the temporary folder used for files is located at <project-dir>\obj\<build-config>. We place copies of source files under that folder.

When you set MvcBuildViews to true the aspnet compiler will be called on the <project-dir> folder.

When you perform a build with MvcBuildViews=true, after a publish you will receive the error that is stated here. That is because the aspnet compiler is including the obj\ folder during that compile since it’s underneath the <project-dir> folder.

In order to prevent the error we need to ensure that the files generated by publish under obj\ are deleted before the aspnet compiler is called. This is a bit tricky because the build config used for Publish is set to Release but Debug for Build. So relying on a typical Clean is not enough (i.e. we need to potentially clean files for a different build configuration).

As a workaround you can place the following elements in the .csproj/.vbproj above the end element for Project (</Project>)

<_EnableCleanOnBuildForMvcViews Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='' ">true</_EnableCleanOnBuildForMvcViews>
<Target Name="CleanupForBuildMvcViews" Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='true' and '$(MVCBuildViews)'=='true' " BeforeTargets="MvcBuildViews">
    <_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\Package\**\*" />
    <_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\TransformWebConfig\**\*" />
    <_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\CSAutoParameterize\**\*" />
    <_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\TempPE\**\*" />

<Delete Files="@(_TempWebConfigToDelete)"/>

Sayed Ibrahim Hashimi
Posted by aspdotnetdev on 5/31/2013 at 5:23 PM
This may be related:
Posted by gopkumr on 5/25/2013 at 11:00 AM
I am also able to reproduce this issue. I am using VS 2012 and trying to build MVC 3.0 project.
Posted by Microsoft on 3/7/2013 at 10:20 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by aspdotnetdev on 3/2/2013 at 11:09 PM
Sorry for the poor formatting. It seems my line breaks were removed when I clicked "submit".
Posted by aspdotnetdev on 3/2/2013 at 11:08 PM
I have attached the file "" (it will only be visible to Microsoft employees). Also, a correction to my previous comment: both machines are Windows 7. Here are the steps to reproduce the error:
-Unzip into the folder c:\cleaned.
-Open the solution "C:\cleaned\2013\Company Websites.sln" in Visual Studio 2012 with Update 1 installed (will also need to be on a machine that has created an Azure Cloud project before).
-Publish the project "Company.Websites". Do a file system publish to the folder "c:\out1" with the release configuration and none of the "file publish options" checked.
-Delete the folder "c:\out1".
-Repeat the publish for "Company.Websites".
-You will get the following error:

Error    178    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.    C:\cleaned\2013\Company.Websites\obj\release\package\packagetmp\web.config    82    0    Company.Websites

I note that the error code is different (178 rather than 20), but the error message and symptoms are the same as indicated in the original error report. If I delete the "obj" folder for the "Company.Websites" project, I can then perform a successful publish again.
Posted by aspdotnetdev on 3/1/2013 at 8:02 PM
I can reproduce this too, on two different computers running different operating systems (Win7/Win8). I will work on uploading a demo project, but it'll take me a bit of time to remove the sensitive info. Also, it's about 30MB, so hopefully there are no file size upload limits.
Posted by Trips2007 on 3/1/2013 at 10:49 AM
No I cannot. It would take significant time for me to gut the project that creates this issue of proprietary code and still have the error occur. However, if there are any files produced by the build and/or publish operations that would be useful in tracking this down, I'm glad to do that.

Note that according to the response on Stack Overflow, this is a pervasive problem that makes the publishing wizard unusable for many. Please do not dismiss this issue because a reproducible use case is not handed to you. It is important, and worth Microsoft taking the time to investigate thoroughly.
Posted by Microsoft on 3/1/2013 at 2:06 AM
Hi Trips2007, so sorry for my late response. Could you upload a demo project please? Thanks.
Posted by Microsoft on 2/21/2013 at 2:55 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(