tldr; Try switching build configurations and also deleting obj
I haven't had this problem for YEARS and suddenly started getting it.
>------ Build started: Project: MyMVC, Configuration: Debug Any CPU ------
6>S:\TFS\RRStore\RRStore.Main\MyMVC\obj\CodeGen\obj\Release\Package\PackageTmp\Areas\Store\Views\Products\Category\SearchPanel\Search.cshtml.cs(22,26,22,27): error CS0116: A namespace cannot directly contain members such as fields or methods
========== Build: 5 succeeded, 1 failed, 9 up-to-date, 0 skipped ==========
Wait a minute! I'm doing a DEBUG build and it is complaining about obj\Release
So I deleted obj
completely and got this error:
15>------ Rebuild All started: Project: MicroPedi_MVC, Configuration: Debug Any CPU ------
15>...RazorGenerator.MsBuild.targets(44,9): error : Could not find a part of the path 'S:\TFS\RRStore\RRStore.Main\My_MVC\obj\Release\Package\PackageTmp\Areas\Admin\Views\CallCenter\Index.cshtml'.
========== Rebuild All: 14 succeeded, 1 failed, 0 skipped ==========
What!! That folder doesn't even exist (obj\Release
)!
So I switched to Release
configuration. Everything built. Now if I recall this doesn't prove anything because I think I'm using pre-compiled views - tbh I forget how it works.
Anyway THEN I switched back to Debug
configuration.
Everything suddenly worked!
If that doesn't help - just try some basic detective work and assume nothing is working!
I found it was building fine on my server and I had made no changes to my web.config in a long long time.
- Try making an inconsequential change to your file (to make sure the codegen is updating). eg. add a comment, classname or change some text
- Find the generated file which will be something like
\obj\CodeGen\obj\Release\Package\PackageTmp\Areas\Store\Views\Products\Products.cshtml.cs
- See if your trivial change is reflected there
- If not delete everything in
\obj\CodeGen\...
or probably in obj
- Build your project
Another possibility:
I had recently installed .NET Framework 1.1 (to be able to extract a 3rd party library I needed).
I uninstalled it anyway, but not clear if this was the reason anything got screwed up. Suspicious though - especially since 1.1. always liked to mess with IIS.