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

前端 未结 4 1258
长发绾君心
长发绾君心 2021-02-07 09:49

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

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-07 10:50

    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!

提交回复
热议问题