ServiceStack turn on Razor intellisense support without MVC

纵然是瞬间 提交于 2019-12-05 08:01:25

In order to get intelli-sense in VS.NET your ASP.NET web application needs to have the necessary build providers registered which tell VS.NET to compiler razor views, what base class to include and what namespaces you want added. You can find an example of the necessary Web.Config in the Razor Rockstars example project.

Note: When you're creating a self-hosting Console Application you also need a copy of the App.Config stored in Web.config (which is what VS.NET looks at, at design-time). The Web.config isn't needed or used beyond development/design time so does.

The necessary web.config info should already be automatically included when you install the ServiceStack.Razor NuGet package. So if you've deleted the web.config transform that was applied to your Web.config, you need to add it back. If you want to copy the web.config.transform file manually you need to manually modify the $rootnamespace$ placeholder with your project namespace, e.g change:

<add namespace="$rootnamespace$" />

to

<add namespace="Amce.MyWebProject" />

Hmmm, It looks like there may be an outstanding issue with intelli-sense on VS 2012, you will need to revert back to using VS2010 until we figure out what the VS.NET team has changed with Razor's build providers.

On top of ensuring that you have the correct <buildProviders> defined in web.config, if you're seeing the following warning when opening .cshtml files in VS.

ASP.NET runtime error: Could not load file or assembly 'ServiceStack.Razor' or one of its dependencies. The system cannot find the file specified.

You need to copy ServiceStack.*.dll and System.Web.Razor.dll into the /bin directory. Thats right, NOT the /bin/debug or /bin/release directories. This will give you full Intellisense support even in a self-hosted project (without needing to create a web project).

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