Get intellisense razor in library project?

I have a business project where I will create emails based on templates made with a razor. How can i get an intellisense razor? Is it as simple as including multiple assemblies or do I need to do something more replicated?

This is for using the RazorEngine library.

+8
c # razor intellisense
source share
2 answers

You need to edit the .csproj file. Add the following ProjectTypeGuids node (add only the ProjectGuid node below).

<ProjectGuid>{28AD1627-3486-48C2-A045-EFFBB441582B}</ProjectGuid> <ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> 

Save the file, then open it again in Visual Studio. VS2012 then does some conversion, but in the end everything is fine. There is a tool.

Depending on what you are doing (Razor Generator?), You will need some links (System.Web, System.Web.WebPages, System.Web.Mvc, System.Web.Razor, System.Web.Routing ...) .

This has been tested with VS2012.

In Visual Studio 2013, I also had to replace the following line in the .csproj file because it indicated a malfunction:

 <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" /> 
+3
source share

This is a good guide to achieve this.

http://thetoeb.de/2014/01/05/enabling-mvc5-intellisense-in-a-classlibrary-project/

Steps:

  • Add the nuget MVC package (5.0) (right-click project in Solution Explorer β†’ Manage NuGet packages β†’ search for MVC and install β€œMicrosoft ASP.NET MVC”)
  • Close all open .cshtml files
  • Right-click project β†’ Properties β†’ Build β†’ change output path to "bin /"
  • Add the following minimal Web.config to the root of your class library project (the web configuration file is required exclusively for intellisense. Configuration (via Web.config) must be done in WebApplication, where your ClassLibrary assembly is located)
  • Clean and create a solution.

Web.config:

 <?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=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /> </sectionGroup> </configSections> <appSettings> <add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Enabled" value="false" /> </appSettings> <system.web> <compilation debug="true" targetFramework="4.5" /> </system.web> <system.web.webPages.razor> <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Optimization"/> <add namespace="System.Web.Routing" /> <!-- add other namespaces for views here --> <!-- eg your own project's, Lib.Views.Etc --> </namespaces> </pages> </system.web.webPages.razor> </configuration> 
+2
source share

All Articles