Skip to content

Commit

Permalink
Razor remove csproj (dotnet#2662)
Browse files Browse the repository at this point in the history
* don't merge

* csproj razor update

* code style

* Update razor.md
  • Loading branch information
Rick-Anderson authored and tdykstra committed Mar 6, 2017
1 parent 3725c8e commit 54641f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
16 changes: 4 additions & 12 deletions aspnetcore/mvc/views/razor.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Razor Syntax Reference | Microsoft Docs
author: rick-anderson
description:
keywords: ASP.NET Core,
description: Details Razor syntax
keywords: ASP.NET Core, Razor
ms.author: riande
manager: wpickett
ms.date: 01/14/2017
Expand Down Expand Up @@ -567,17 +567,9 @@ C# Razor keywords need to be double escaped with `@(@C# Razor Keyword)`, for exa

## View compilation

Razor views are compiled at runtime when the view is invoked. If your app targets ASP.NET Core 1.1.0 and you prefer to compile your Razor views and deploy them with your app, make these changes to *project.json*:
Razor views are compiled at runtime when the view is invoked. ASP.NET Core 1.1.0 and higher can optionally compile Razor views and deploy them with the app. To do this set `MvcRazorCompileOnPublish` to true and include a package reference to `Microsoft.AspNetCore.Mvc.Razor.ViewCompilation`. The following *.csproj* sample highlights these settings:

1. Add a reference to "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Design" under the "dependencies" section.
2. Add a reference to "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tools" under the "tools" section.
3. Add a postpublish script to invoke the view compiler:

```json
"scripts": {
"postpublish": [ "dotnet razor-precompile --configuration %publish:Configuration% --framework %publish:TargetFramework% --output-path %publish:OutputPath% %publish:ProjectPath%" ]
}
```
[!code-html[Main](razor\sample\MvcRazorCompileOnPublish.csproj?highlight=4,15)]

> [!NOTE]
> View lookups are case sensitive. If your controller routing seeks a view named `Index` (*Index.cshtml*) but you've named your view file `index` (*index.cshtml*), you'll receive an exception: `InvalidOperationException: The view 'Index' was not found.`
Expand Down
21 changes: 21 additions & 0 deletions aspnetcore/mvc/views/razor/sample/MvcRazorCompileOnPublish.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
</PropertyGroup>

<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="1.1.0-*" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0-msbuild3-final" />
</ItemGroup>

</Project>

0 comments on commit 54641f4

Please sign in to comment.