Project Description

MSBuild tool to generate client-side (JavaScript using SharpKit) view templates using Razor syntax.


This project transform views files with Razor syntax (used in Microsoft ASP.NET MVC) to classes that can be transformed to client-side JavaScript using SharpKit.

Resulting scripts can be used as templates to use on webpages on client-side.


  • .Net Framework 4.5 Beta (can be compiled in 4.0 using source code)
  • ASP.NET Razor 2.0 (can be found in ASP.NET MVC 4 or ASP.NET Web Stack)
  • SharpKit v4.25.3000 (or higher, or even lower :)


Mark razor views to transform with special name in .csproj:
<View Include="SampleView.cshtml"/>
<View Include="Folder\OtherView.cshtml"/>

Include MSBuild task:
<UsingTask TaskName="XWeb.SharpKit.Razor.MSBuild.Generate" AssemblyFile="path to dll\XWeb.SharpKit.Razor.MSBuild.dll" />

Call task in build process before compiling:
<Target Name="BeforeBuild">
      <Output TaskParameter="GeneratedOutputFiles" ItemName="GeneratedView" />
    <Compile Include="@(GeneratedView)" Exclude="@(Compile)" />
    <Compile Include="Views.generated.cs" Exclude="@(Compile)" />

In this section:
  • InputFiles required parameter is views to transform, used @(View) set.
  • Namespace is the root namespace to generate classes in. Views in nested folders is placed in nested namespaces with same path. Required parameter.
  • RootFolder represents root folder to determinate namespace relative path of views. Required parameter.
  • ViewsInfoFile specifies filename to generate with views info. It can be included to the project to use strongly-typed views execution. Optional, if omited it does not generated.
  • Output GeneratedOutputFiles represends generated output files (Folder/file.cshtml -> Folder.generated.cs). This file set is stored to @(GeneratedView) set.
  • After task execution, resulting files included to @(Compile) set, using <ItemGroup> instruction. Exclude="@(Compile)" used for prevent double inclusion, if generated files is already inlcuded to project. ViewsInfoFile** 'Views.generated.cs' also included to compile.
After this, must be placed SharpKit's target to transform C# to JavaScript after build:
<Import Project="$(MSBuildBinPath)\SharpKit\4\SharpKit.Build.targets" />

This instruction will generate after build the project .js file(s).

Details documentation

It comes soon ;)

Last edited Apr 20, 2012 at 8:47 AM by Igorbek, version 8