Search code examples
nancyasp.net-core-1.0

Nancyfx Views not found when debugging ASP.NET Core 1.0 application


Am having problems resolving Nancyfx views with Asp.net Core 1.0 in debug mode. This is because folders like wwwroot are not output in the bin folder. I've googled but have not found anyways of sending folders to bin/Debug. However when I published and run the app the views are resolved fine. This is because the project.json I can configure for folders to be outputted. I know I can customize the ViewLocations but if I do so for it to work in debug then it will not work when published.


Solution

  • You have couple of options here:

    1. Setup the ContentRoot. The following code uses the project directory as the location for views.

          public class Program
          {
              public static void Main(string[] args)
              {
                  var host = new WebHostBuilder()
                      .UseKestrel()
                      .UseContentRoot(Directory.GetCurrentDirectory())
                      .UseIISIntegration()
                      .UseStartup<Startup>()
                      .Build();
      
                  host.Run();
              }
          }
      
    2. You can use the copyToOutput node in project.json for this purpose.

      Example:

      "buildOptions": {
        "copyToOutput": {
          "include": [
            "Areas",
            "Views",
            "wwwroot",
            "config.json",
            "web.config"
          ]
        }