dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.83k stars 654 forks source link

.cshtml view not found #1252

Open thienedits opened 7 years ago

thienedits commented 7 years ago

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview2-003131)

Product Information:
 Version:            1.0.0-preview2-003131
 Commit SHA-1 hash:  635cf40e58

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64

VS Code version: 1.9.1 C# Extension version: 1.7.0

Steps to reproduce

In the root folder I have a Controllers and Views folders. I am creating a simple view,

CategoriesController.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace DiceWeb6.Controllers
{
    public class CategoriesController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }
        public IActionResult Cat()
        {
            return View();
        }
        public IActionResult CategoriesCreator()
        {
            return View();
        }

  }
}

Views/Categories folder contains Cat.cshtml

Expected behavior

hitting http://localhost:58927/Categories/Cat should return the html file

Actual behavior

Getting a 404 error, page can't be found. If I create the code in Visual Studio and then open in vscode, the page renders. However anything I create in vscode does not return the html.

Request starting HTTP/1.1 GET http://localhost:58927/Categories/Cat  
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:58927/Categories/Cat  
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 31.0532ms 404 
Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.Dev.Request","time":"2017-02-19T05:49:15.2043710Z","tags":{"ai.operation.id":"4LbqNEBn5fk=","ai.internal.sdkVersion":"aspnet5c:1.0.0","ai.operation.name":"GET /Categories/Cat","ai.device.roleInstance":"Eels","ai.user.userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"},"data":{"baseType":"RequestData","baseData":{"ver":2,"id":"4LbqNEBn5fk=","name":"GET /Categories/Cat","startTime":"2017-02-19T05:49:15.2043710+00:00","duration":"00:00:00.0208079","success":false,"responseCode":"404","url":"http://localhost:58927/Categories/Cat","httpMethod":"GET","properties":{"DeveloperMode":"true"}}}}
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 31.0532ms 404
eByte23 commented 7 years ago

@thienedits could you provide your project.json

seems like you need this part in it if you do not already

 "publishOptions": {
        "include": [
            "**/*.cshtml",
        ]
    }
thienedits commented 7 years ago

Cool I added it and now it works. Thanks.

thienedits commented 7 years ago

Hello I don't this is working. I thought it worked before because I readded a .cshtml file with the same that was deleted. When i create a new .cshtml its still the same error.

project.json

{
  "dependencies": {
    "EdCanHack.DiceNotation": "0.2.0",
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.NETCore.Portable.Compatibility": "1.0.1",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    }
  },

  "tools": {
    "BundlerMinifier.Core": "2.0.238",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config",
      "**/*.cshtml"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}
gregg-miskelly commented 7 years ago

@thienedits this isn't a problem with the C# extension, and I don't know how many people here are experts on ASP.NET so you may have more luck asking your question in another repo.

That said, here are the differences that you might see when launching your app from VS Code vs. the command line:

  1. In earlier versions of the launch.json generator, we would default the current working directory to the workspace root instead of the project root. If you directory you are opening isn't the project directory, you could try changing that to see if it helps.
  2. We default to launch the web server in development mode (see env section of launch.json).