Visual Studio's Publish feature prevents my ASP.NET MVC application from compiling

I noticed a strange problem when FTP publishing my ASP.NET MVC application in Visual Studio:

After publication, it will not compile. I get this error:

An error occurred while using a section registered as allowDefinition = 'MachineToApplication' that is higher than the application level. This error can be caused by the fact that the virtual directory is not configured as an application in IIS.

From my research so far, this error usually occurs when a Web.config file containing certain sections is deeper than root in the project folder hierarchy.

Well, it turns out I have some Web.config files deeper in the hierarchy that I found in these folders:

  • [project folder] \ obj \ Release \ Package \ PackageTmp
  • [project folder] \ obj \ Release \ TransformWebConfig \ original
  • [project folder] \ obj \ Release \ TransformWebConfig \ transform

The problem is that I did not place these files in these places. They are copied there during the publishing process (in particular, FTP publish). If I manually delete Web.configs (or rebuild my solution), I can compile again. (Well, rebuilding usually works β€” it won’t work if I switch from Debug to Release or vice versa after posting.)

Now, to my questions:

Am I messing up the setup or doing something wrong or is it basically just a nuisance that I have to deal with? Should I be bothered? Is this problem fixed?

+4
source share
1 answer

Are you using <MvcBuildViews>true</MvcBuildViews> in your web project .csproj file? if so, this could be a problem. Put it on false and the problem will disappear.

Another solution, if you really want to use the MvcBuildViews function, is described here: link . I have not tested it, but it seems to have had good reviews!

+5
source

All Articles