Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

allowDefinition='MachineToApplication' msbuild error

We have a ASP.NET MVC with 4-5 different build configurations. Whenever we change the build configuration, we need to delete the obj folder for the web project, since we get the 'allowDefinition='MachineToApplication' error. A pain, but we managed by deleting the folder in pre/post build events. Now I need to configure our CI to build deployment packages. This means that I cannot delete the obj folder. Every time I compile e.g. with the following msbuild parameters

/p:CreatePackageOnPublish=true /p:DeployOnBuild=true

I recieve the error:

web.config(123): error ASPCONFIG: 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.

As far as I understand, the problem is that there's multiple .config files in the project - In our case, there's not. I could really use some help to find an explanation and find a permanent (no- hack) fix.

Edit: This question is marked as a duplicate, but the corresponding answers and cause(s) in the 2 threads, are clearly different from each other. Not sure what is intended with this tag - I've read that particular post before posting this question, as it didn't answer my question. There's multiple causes for this error message. It is 'similar', but definitely not a duplicate!

like image 487
jaspernygaard Avatar asked Mar 11 '11 09:03

jaspernygaard


2 Answers

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.

like image 135
Marnix van Valen Avatar answered Sep 27 '22 18:09

Marnix van Valen


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?

like image 38
Valamas Avatar answered Sep 27 '22 18:09

Valamas