Error: The type exists in both directories

前端 未结 19 1826
北恋
北恋 2020-12-14 14:13

In a MVC2 project I moved a file from App_code to Content folder and compiled it. Then move it back again to App_Code and then changed its Build Action to \"Compile\". Now I

19条回答
  •  囚心锁ツ
    2020-12-14 14:51

    The App_Code folder isn't intended to be used with MVC Projects (WAP).

    Files in the App_Code folder gets compiled automatically as part of a special dll. If the Build Action property on the file is set to Compile, the same class will also get compiled as part of the main dll and you will end up with two copies.

    Setting the Build Action property to None makes sure there is only one copy of the class in the project. The compiler will not catch any errors in the App_Code folder when building but Intellisense will still validate the code but compile-time errors won't show up until it is compiled on-the-fly.

    The recommended solution is to put code in a normal folder and make sure the Build Action is set to Compile.

提交回复
热议问题