Problem/Solution: Error in publishing ASP.NET MVC with MvcBuildViews ON from Visual Studio 2012
Note: This post is contributed by Matthew Seng. He is one of my colleagues and we are working in same project together.
Error Message
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.
Steps to replicate the issue
- Create a new ASP.NET MVC 4 project in Visual Studio 2012
- Set true to MvcBuildViews in csproj (
<MvcBuildViews>true</MvcBuildViews>
) - Publish the project. (Observe: it will work fine.)
- Publish it again (Observe: You will see the error message and you won’t be able to publish the project anymore)
Temporary solution:
- Delete obj folder from your MVC project.
Permanent solution:
- Delete obj folder from your MVC project.
- Add the following below the MvcBuildViews property:
<BaseIntermediateOutputPath>..\obj</BaseIntermediateOutputPath>
Root cause:
MvcBuildViews
property (This is to allow view errors to be shown when building solution) set to true in project file and multiple web.config confuses compiler. Learn more at: