Simon Lomax
Simon Lomax

Reputation: 8972

Problem after publishing web application from VS 2010

Whenever I publish my MVC web application in VS 2010 via the One-click publish feature (I'm not doing any web.config transforms or anything fancy - yet!). The next time I come to build the app I get the following error:

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. in ...MyWebApp\obj\release\package\packagetmp \web.config

A new copy of the web.config file is indeed created by VS2010 below the ...MyWebApp\obj\ folder so I deleted the whole obj folder and I was then able to build again.

But I shouldn't have to do that each time I publish - I must have something configured incorrectly - can anyone help please.

Thanks.

Upvotes: 1

Views: 1699

Answers (2)

CraigTP
CraigTP

Reputation: 44919

This is unfortunately a known issue with Publishing a web application to the file system. This still affects the release version (RTM) of Visual Studio 2010. It's not limited to the Beta or RC versions.

This problem "bit" me also, and I too was having to manually delete the Debug and Release folders inside the obj folder within my web site solution folder.

The real answer for an automated "workaround" can be found in this answer to the other Stack Overflow question:

Why do I randomly get a “error to use section registered as allowDefinition='MachineToApplication'” when building an MVC project?

In a nutshell, you need to delete the web.config files from either the Debug or Release folders (or both!), and that's achieved with a pre-build command (configured in the Build Events tab of the Project Properties page of your solution):

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

Personally, I delete the entire obj folder since all those files are re-created with each build anyway.

Upvotes: 1

Alan Savage
Alan Savage

Reputation: 842

I have just found a work around for this that has worked for me, open the .csproj for your web project and change the node under the Project\PropertyGroup node to this:

from this: <MvcBuildViews>true</MvcBuildViews>

to this: <MvcBuildViews>false</MvcBuildViews>

This has worked for me, hopefully it will work for you also.

Upvotes: 0

Related Questions