Compiler error: ASP.NET Empty Project with Servicestack.Razor.BuildTask library

  • Create a ServiceStack ASP.NET Empty Project.
  • Add “Servicestack.Razor.BuildTask” library to the web project using Nuget.
  • Compile the web project and you will get the following error message: The “ServiceStack.Razor.BuildTask.RazorGeneratorBuildTask” task could not be loaded from the assembly [ProjectRootFolder]\packages\ServiceStack.Razor.BuildTask.5.5.0\build\ServiceStack.Razor.BuildTask.dll. Could not load file or assembly ‘file:///[ProjectRootFolder]\packages\ServiceStack.Razor.BuildTask.5.5.0\build\ServiceStack.Razor.BuildTask.dll’ or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [ProjectName]

VS: 2017
.NET Framework: 4.5
ServiceStack Version: 5.5.0
OS: Windows 10

This should now be resolved from using the latest v5.5.1 packages which is now available on MyGet.

I am getting another error after updating to v5.5.1: The type ‘ViewPage’ exists in both ‘ServiceStack.Razor.BuildTask, Version=, Culture=neutral, PublicKeyToken=02c12cbda47e6587’ and ‘ServiceStack.Razor, Version=, Culture=neutral, PublicKeyToken=02c12cbda47e6587’

Make sure to include at least one razor view in the web project to get the error message above.

It should be resolved by removing Servicestack.Razor.BuildTask NuGet package, clearing your NuGet packages cache then installing the Servicestack.Razor.BuildTask package again to install the latest version.