## Web.config Error in Build after Publish

If you publish an ASP.Net (MVC) application in VS 2010, you need to define a Target Location in the Publish… dialog.

VS then builds and publishes. Another manual build will result in the error message

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

For better entertainment, the file name that causes the error is displayed as “web.config” in the Error List window.

Right-click and select Copy will fill the clipboard with the real file path, which is

C:\path\to\project\obj\debug\package\packagetmp\web.config

which is a relict of the publishing process.

The solution is to delete everything from the obj\Debug and obj\Release directories (depending on your build configuration) and build again.

Update

Executing “Clean Solution” or “Clean Project” also solves the problem.

Advertisements

### One Response to Web.config Error in Build after Publish

1. […] I encountered this error message before, and in that case you should be able to solve the problem by running Clean on the project or the […]