allowDefinition='MachineToApplication' msbuild error

There is a similar question here on SO with some good solutions for this issue.

The problem is that building a deployment package creates a copy of the web.config in a subfolder of /obj. That will normally be be cleared out if you do a rebuild or a clean. However, if you build a deployment package in one configuration (e.g. Debug) and then switch to another confguration (e.g. Release) the obj/Debug folder is not cleared out and the web.config file there causes problems.

The quick solution is to clean all configurations and then do a (re)build. Alternatively you could delete the /obj folder in your project. To permanently resolve the issue you can either move the intermediate output (/obj) out of your project folder or modify the project to force a clean of all configurations on rebuild.


I too was deleting the obj folder until I had a conflict with a build script which required it. Catch-22, I used the accepted answer on the following SO link to move the location of the Obj folder to C:\Temp\BUILD. You have to do it per csproj file, but it is a great solution.

Here is the link: VisualStudio: How to save the obj folder somewhere else

Note that I am using a variable for the project name. R:\Temp\Build\Debug\$(MSBuildProjectName)

I have the above line in both debug and release sections for all my projects, including class projects. My build path is a ram drive for speed. See this SO for more info: How to access macro variables within csproj file?


I just answered a similar question here. To recap, I ran into this problem 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.