ServiceStack includes support for Razor intellisense without MVC

I installed SS.Razor in my test project. If I just change default.htm -> cshtml, it works, but without syntax support vs intellisense. Thus, the razor code is black and white text.

I wonder how to enable Razor without opening the project as a .net MVC project. Thanks!

EDIT ------------------------------------------

Here is my web.config

(note the addition of the extension = ".cshtml" ... is ...)

<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup> </configSections> <appSettings> <add key="webPages:Enabled" value="false" /> </appSettings> <connectionStrings /> <!-- For a description of web.config changes for .NET 4.5 see http://go.microsoft.com/fwlink/?LinkId=235367. The following attributes can be set on the <httpRuntime> tag. <system.Web> <httpRuntime targetFramework="4.5" /> </system.Web> --> <system.web> <compilation debug="true" targetFramework="4.5"> <assemblies> <add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </assemblies> <buildProviders> <add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor" /> </buildProviders> </compilation> <!-- The <authentication> section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user. --> <authentication mode="Windows" /> <!-- The <customErrors> section enables configuration of what to do if/when an unhandled error occurs during the execution of a request. Specifically, it enables developers to configure html error pages to be displayed in place of a error stack trace. <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors> --> <httpHandlers> <add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" /> </httpHandlers> <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" /> </system.web> <!-- The system.webServer section is required for running ASP.NET AJAX under Internet Information Services 7.0. It is not necessary for previous version of IIS. --> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <handlers> <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" /> </handlers> </system.webServer> <system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <pages pageBaseType="ServiceStack.Razor.ViewPage"> <namespaces> <add namespace="ServiceStack.Html" /> <add namespace="ServiceStack.Razor" /> <add namespace="ServiceStack.Text" /> <add namespace="ServiceStack.OrmLite" /> <add namespace="Backbone.Todos" /> </namespaces> </pages> </system.web.webPages.razor> </configuration> 
+6
source share
2 answers

To get intelli-sense in VS.NET, your ASP.NET web application must have registered registered assembly providers that tell VS.NET about compiler razor views, which base class to include, and which namespaces you want to add. You can find an example of the desired Web.Config in the example Razor Rockstars project .

Note. When you create a console application for self-hosting, you also need a copy of App.Config stored in Web.config (which VS.NET looks at during development). Web.config is not required or used outside of development / development time, so it does.

The necessary web.config information should be automatically included when you install the ServiceStack.Razor NuGet package. Therefore, if you removed the web.config transformation 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 change the $rootnamespace$ placeholder in the project namespace, for example, change:

 <add namespace="$rootnamespace$" /> 

to

 <add namespace="Amce.MyWebProject" /> 

Hmmm. It looks like intelli-sense might be a problem on VS 2012, you will need to revert to using VS2010 until we find out what the VS.NET team has changed with the Razor build providers.

+5
source

Instead of making sure that you have the correct <buildProviders> defined in the web.config file if you see the following warning when opening .cshtml files in VS.

ASP.NET runtime error: Failed to load file or assembly "ServiceStack.Razor" or one of its dependencies. The system cannot find the specified file.

You need to copy ServiceStack. * .dll and System.Web.Razor.dll to the / bin directory. That's right, NOT the / bin / debug or / bin / release directories. This will give you full Intellisense support even in a standalone project (without creating a web project).

+3
source

Source: https://habr.com/ru/post/926913/


All Articles