简体   繁体   English

将Webpack与ASP.NET Core 1.1一起使用

[英]Using Webpack with ASP.NET Core 1.1

I'm trying to use Webpack with my ASP.NET Core 1.1 app. 我正在尝试将Webpack与我的ASP.NET Core 1.1应用程序一起使用。 I'm using the .NET Core preview for 1.1 that was just released, though I only just upgraded to 1.1 and was using 1.0 previously, I was still having the same issue. 我正在使用刚刚发布的1.1版.NET核心预览,虽然我刚刚升级到1.1并且之前使用的是1.0,但我仍然遇到了同样的问题。

Following: https://github.com/xabikos/aspnet-webpack , I've added Webpack: 3.0.0 to my project.json file and ran the command dotnet restore , however, when I try and register the service ie services.AddWebpack() I get the following error: 以下: https//github.com/xabikos/aspnet-webpack ,我已将Webpack: 3.0.0添加到我的project.json文件并运行命令dotnet restore ,但是,当我尝试注册服务即services.AddWebpack()我收到以下错误:

error CS1061: 'IServiceCollection' does not contain a definition for'AddWebpack' and no extension method 'AddWebpack' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive o assembly reference?)

project.json project.json

{
     "version": "1.0.0-*",
       "dependencies": {
         "Microsoft.AspNetCore.Diagnostics": "1.0.0",
         "Microsoft.AspNetCore.Mvc": "1.0.1",
         "Microsoft.AspNetCore.Razor.Tools": {
              "version": "1.0.0-preview2-final",
              "type": "build"
               },
         "Microsoft.AspNet.SignalR.Client": "2.2.1",
         "Microsoft.AspNetCore.SignalR.Server": "0.1.0-rtm-21431",
         "Microsoft.AspNet.SignalR.SystemWeb": "2.2.1",
         "Microsoft.AspNet.SignalR.JS": "2.2.1",
         "Microsoft.AspNetCore.WebSockets.Server": "0.1.0-rc2-final",
         "System.Xml.XmlSerializer": "4.0.11",
         "React.AspNet": "3.0.0-rc1",
         "Microsoft.AspNetCore.Routing": "1.0.1",
         "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
         "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
         "Microsoft.AspNetCore.StaticFiles": "1.0.0",
         "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
         "Microsoft.Extensions.Configuration.Json": "1.0.0",
         "Microsoft.Extensions.Configuration.CommandLine": "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.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
         "Microsoft.Owin.Host.SystemWeb": "3.0.1",
         "Microsoft.Owin": "3.0.1",
         "Microsoft.Owin.Security": "3.0.1",
         "Webpack": "3.0.0"
     },
      "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" 
      }, 
      "frameworks": {
          "netcoreapp1.1": {
               "dependencies": {
                    "Microsoft.NETCore.App": {
                          "version": "1.1.0-preview1-001100-00",
                          "type": "platform"
                     }
                },
                "imports": [
                    "net451",
                    "dnxcore50"
                  ]
                 }
            },
       "buildOptions": {
          "emitEntryPoint": true,
          "preserveCompilationContext": true
       ,
      "runtimeOptions": {
           "configProperties": {
               "System.GC.Server": true
               }
            },
       "publishOptions": {
            "include": [
                "wwwroot",
                "**/*.cshtml",
                "appsettings.json",
                "web.config"
                ]
       },
      "scripts": {
      "precompile": [ "dotnet bundle" ],
      "prepublish": [ "bower install" ],
      "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
},
      "tooling": {
      "defaultNamespace": "Rebellion"
     }
 }

startup.cs startup.cs

public void ConfigureServices(IServiceCollection services)
{
     // Add framework services.
     services.AddMvc();
     services.AddSignalR();
     services.AddWebpack();
}

As far as i can tell this should work and I dont know what I'm missing. 据我所知,这应该工作,我不知道我错过了什么。 I have a feeling my project.json is screwy. 我有一种感觉,我的project.json很棘手。

If I had to guess, I'd say you haven't got a using Webpack; 如果我不得不猜测,我会说你没有using Webpack; at the top of your Startup.cs file. 在Startup.cs文件的顶部。 If you're using Visual Studio it should offer to add it for you if you right click on the error and click "Quick Actions and Refactorings..." or press Ctrl+. 如果您正在使用Visual Studio,如果您右键单击错误并单击“快速操作和重构...”或按Ctrl +,它应该为您添加它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM