15
votes

I have seen a few questions on SO about a similar error when deploying a website, but I seem to randomly get this error when building an ASP.NET MVC website in Visual Studio. Performing a clean usually fixes it, but is there any way to avoid this completely?

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. d:...\obj\debug\package\packagetmp\web.config

Note that it is complaining about the root web.config, not the one from the Views subdirectory.

4
Same problem being experienced here, I am using VS2010 RC1 on Windows 7 ASP.NET MVC 1.0CmdrTallen
I experienced it on VS2010 Beta 2 and RC on Windows 7 with ASP.NET MVC 2Jedidja
This is exactly the same in VS2010 Express - the released version, wasted ages of my time.ilivewithian

4 Answers

15
votes

I assume you're using the publish feature. I'm getting this error when using publish to a file directory.

Publishing your app creates a temporary copy of your application in the \obj\debug\package\packagetmp\web.config directory.

That web.config confuses the IDE which thinks it is an application, but its not in a virtual directory so you get the error.

Workaround:

It's a simple workaround to add this to a pre-build command:

 del "$(ProjectDir)\obj\Debug\Package\PackageTmp\web.config"

Failed workarounds:

  • Changing the directory for 'Location where package will be created' under 'Package/Publish Web' settings doesn't seem to have an effect - even if you get clever and try to put it outside the project root with ......

  • Creating an actual virtual directory in IIS for 'PackageTmp' didn't fix it either!

CONNECT ISSUE:

http://connect.microsoft.com/VisualStudio/feedback/details/503254/web-config-in-package-folder-makes-it-impossible-to-compile-debug

I hope they fix this in the RC!

9
votes

I was unable to get the other workaround to work, but the following pre-build event seemed to work for me:

rmdir /s /q "$(ProjectDir)obj\Debug\Package"
rmdir /s /q "$(ProjectDir)obj\Debug\TransformWebConfig"
rmdir /s /q "$(ProjectDir)obj\Release\Package"
rmdir /s /q "$(ProjectDir)obj\Release\TransformWebConfig"
2
votes

I answered a similar question recently, and this looks like it might be related.

To summarize, I ran into this in one of our MVC projects, and it was due to having the MvcBuildViews property in the project file set to true. Setting the property to false fixed the problem.

<MvcBuildViews>false</MvcBuildViews>

I also found this answer which outlines an alternative that does not require turning off view building.

0
votes

You can safely put this target build at the end of your .csproj file and leave MvcBuildViews to true.

It deletes the obj folder before starting the build...

  <Target Name="BeforeBuild">
    <!-- Remove obj folder -->
    <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
  </Target>