Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Fixed Help for as Fixed


34
0
Sign in
to vote
Type: Bug
ID: 779737
Opened: 2/21/2013 12:26:02 PM
Access Restriction: Public
2
Workaround(s)
view
14
User(s) can reproduce this bug

Description

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.    
E:\MyProjectPath\obj\release\csautoparameterize\original\web.config

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:

http://stackoverflow.com/q/1712629/141172

http://stackoverflow.com/q/2355947/141172
Details
Sign in to post a comment.
Posted by Microsoft 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 Microsoft 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>)

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

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

Sayed Ibrahim Hashimi
Posted by aspdotnetdev on 5/31/2013 at 5:23 PM
This may be related: http://connect.microsoft.com/VisualStudio/feedback/details/556312/mvcbuildviews-does-not-play-well-with-one-click-publish
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 "2013.zip" (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 2013.zip 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(http://support.microsoft.com)
Sign in to post a workaround.
Posted by tanaka_733 on 12/10/2013 at 10:42 PM
This is almost a nice workaround, but one more line is required for our environment (possibly VS2013?).

<PropertyGroup>
    <_EnableCleanOnBuildForMvcViews Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='' ">true</_EnableCleanOnBuildForMvcViews>
</PropertyGroup>
<Target Name="CleanupForBuildMvcViews" Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='true' and '$(MVCBuildViews)'=='true' " BeforeTargets="MvcBuildViews">
    <ItemGroup>
     <_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\Package\**\*" />
     <_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\TransformWebConfig\**\*" />
     <!-- Add below line -->
     <_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\ProfileTransformWebConfig\**\*" />
     <_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\CSAutoParameterize\**\*" />
     <_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\TempPE\**\*" />
    </ItemGroup>

    <Delete Files="@(_TempWebConfigToDelete)"/>
</Target>
Posted by Microsoft 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>)

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

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

Sayed Ibrahim Hashimi
File Name Submitted By Submitted On File Size  
2013.zip (restricted) 3/2/2013 -