Has anyone else encountered this in VS 2013? Any way of fixing?
Create a new asp.net web application with visual studio 2013.
Under "Add folders and core references for:", check MVC. Click OK.
Open the web.config and copy the contents.
Add a new text template to your project called "Web.tt"
Paste in the contents of your web.config and change the output extension to be .config. all you need is this line (and then your web.config contents after it): <#@ output extension=".config" #>
Make sure there is no whitespace between the output extension line and the first line of your pasted web.config.
Delete the web.config (including release and debug build targets) so that web.tt is all you have for web.config.
Right click on Web.tt and run custom tool. Make sure web.config is created and now part of your project.
Right click on Controllers folder and select Add -> Controller...
Select MVC 5 Controller - Empty and Click Add.
Name your controller and click Add.
Results:
Error There was an error running the selected code generator: ' Value does not fall within the expected range.'
It happen to me because i exclusive web.config out of my project.
I believe this is a bug in Visual Studio with MVC5. To work around it, instead of generating the web.config from a T4 template, we ended up using XML transformations for each build environment.
Microsoft got back to me and they said this is by design...
Resolution
Web.config cannot be deleted to add controller as it is by design. Visual Studio will collapse if web.config is modified underneath.
Workaround:
Config files can include other config files.Web.config include a extensions.config and make an extensions.tt that just generates extensions.config.
Reference : Can a web.config read from an external xml file?
With your consent I am going ahead and closing the case. Please feel free to get back to me if you have any follow-up questions.
Thank you for choosing Microsoft!