Using Webpack with ASP.NET Core 1.1

I am trying to use Webpack with my ASP.NET Core 1.1 application. I am using the .NET Core preview for version 1.1, which has just been released, although I just upgraded to 1.1 and used 1.0 before, I still had the same problem.

Following: https://github.com/xabikos/aspnet-webpack , I added Webpack: 3.0.0 to my project.json file and executed the dotnet restore command, however, when I try to register the service, i.e. services.AddWebpack() I get the following error:

 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

 { "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

 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 don’t know what I am missing. I feel like my project.json shy.

+5
source share
1 answer

If I had to guess, I would say that you do not have using Webpack; at the top of your Startup.cs file. If you are using Visual Studio, he should offer to add it for you if you right-click on the error and click "Quick Actions and Refactoring ..." or press Ctrl +.

+1
source

Source: https://habr.com/ru/post/1258970/


All Articles