Precompile ASP.NET Core MVC 1.1 Views with Visual Studio 2017

Compilation Guide

You can use the file publish functionality in Visual Studio 2017 to produce a precompiled views DLL file.

About this task

You can precompile your application using the Visual Studio Publish feature in the following steps, or you can automate the precompilation using the MSBuild command-line tool.

For ASP.NET Core MVC 1.1, you must add the NuGet package Microsoft.AspNetCore.Mvc.Razor.ViewCompilation or edit the CSPROJ file as described in steps 1—7. You can then precompile your application using the Visual Studio Publish feature in steps 8—12 or you can use the MSBuild command-line tool instead of that procedure.

Note: If you are using ASP.NET Core MVC 2.0, follow the procedures in Precompiling ASP.NET Core MVC 2.0 Views with Visual Studio 2017 because you do not need to add the package or edit the CSPROJ file.

Procedure

  1. In Visual Studio 2017, go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution.
  2. Browse for the NuGet package Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.
  3. Select the options shown below, specifically version 1.1.0.
  4. Click Install to add the package to ASP.NET Core 1.1.
  5. From the Solution Explorer, right-click the web application project file, and select Edit .csproj.
  6. In the property group section of the CSPROJ file, add <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>.
  7. Save and close the .csproj file to reload the project.
  8. From the Solution Explorer, right-click the web application project file and select Publish....
  9. Verify the Configuration is set to Debug.
  10. From the Publish tab of your web application, create a folder, and click Publish.


    The output folder contains the application binaries in combination with the precompiled views.
  11. After precompiling the web application, zip the folder containing the published output, and upload it to the Veracode Platform by clicking Add in the Additional Files section.


  12. Scan the folder used for the precompilation file output.