Web.tt in VS 2013 MVC project causes error “value does not fall within the expected range”

狂风中的少年 提交于 2019-12-23 14:24:17

问题


Has anyone else encountered this in VS 2013? Any way of fixing?

  1. Create a new asp.net web application with visual studio 2013.

  2. Under "Add folders and core references for:", check MVC. Click OK.

  3. Open the web.config and copy the contents.

  4. Add a new text template to your project called "Web.tt"

  5. 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" #>

  6. Make sure there is no whitespace between the output extension line and the first line of your pasted web.config.

  7. Delete the web.config (including release and debug build targets) so that web.tt is all you have for web.config.

  8. Right click on Web.tt and run custom tool. Make sure web.config is created and now part of your project.

  9. Right click on Controllers folder and select Add -> Controller...

  10. Select MVC 5 Controller - Empty and Click Add.

  11. 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.'


回答1:


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!




回答2:


It happen to me because i exclusive web.config out of my project.

Just include web.config back and everything ok.



回答3:


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.



来源:https://stackoverflow.com/questions/21946380/web-tt-in-vs-2013-mvc-project-causes-error-value-does-not-fall-within-the-expec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!