在没有Microsoft.NET.Sdk.Web的情况下使用Razor
发布时间:2020-09-02 02:41:02 所属栏目:Windows 来源:互联网
导读:我正在编写简单的consoleApp(netcoreapp2.0) Project Sdk=Microsoft.NET.Sdk 并希望用mvc运行webserver. class Program{ static void Main(string[] args) { WebHost.CreateDefaultBuilder() .Co
我正在编写简单的consoleApp(netcoreapp2.0) <Project Sdk="Microsoft.NET.Sdk"> 并希望用mvc运行webserver. class Program { static void Main(string[] args) { WebHost.CreateDefaultBuilder() .ConfigureServices(services => services.AddMvc()) .Configure(app => app.UseDeveloperExceptionPage().UseMvcWithDefaultRoute()) .UseHttpSys().Build().Run(); } } public class HomeController : Controller { [HttpGet] public ActionResult Index() => View("Index"); } GET http // localhost:5000时收到错误
可能的原因是Razor Engine. namespace ConsoleApp1 { class Program { static void Main(string[] args) { WebHost.CreateDefaultBuilder() .ConfigureServices(services => services.AddMvc()) .Configure(app => app.UseDeveloperExceptionPage().UseMvcWithDefaultRoute()) .UseHttpSys().Build().Run(); } } public class HomeController : Controller { [HttpGet] public string Index() => "Hello World!"; } } 的csproj <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Server.HttpSys" Version="2.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" /> </ItemGroup> </Project> (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Windows – Win7 Virtualbox在尝试启动虚拟机时出现此错误:
- Windows Server 2016-WinSer 2016标准版与数据中心版的区别
- Windows Server 2016-Hyper-V 2016新增功能
- wcf – 有关替换Microsoft .NET的Web服务增强功能(WSE)3.0的
- 汇编 – 我的.exe程序不是我的预期
- windows – 为什么模拟会话中定义的DOS设备不会出现在资源管
- npm ERR!注册表错误解析json – 尝试在Windows 8中安装Cor
- windows10下安装source insight 4.0
- windows-installer – installshield和windowsinstaller之间
- windows – CFileDialog :: OnInitDialog()不调用
推荐文章
站长推荐
- 在[Windows Subsystem for Linux]中安装perl模块
- api-ms-win-crt-runtime-|1-1-0.dll丢失的解决方
- windows10 安装python.msi出现error 2502/2503解
- 命令行 – 批处理脚本 – 更改桌面上文件夹的图标
- .net – Windows Azure上的AspPDF和AspJPEG
- Windows Phone 7 – Windows Phone开发Visual St
- windows-phone-8.1 – 如何检测在Windows 10 Mob
- 类共享警告不允许我使用visualVM在本地(Windows)
- 使用Windows Power Management API调暗监视器
- windows-8 – 地铁样式Windows 8应用程序是否支持
热点阅读