gpt4 book ai didi

c# - 在 ASP.NET Core 1.1 中使用 Webpack

转载 作者:太空狗 更新时间:2023-10-29 23:43:48 29 4
gpt4 key购买 nike

我正在尝试将 Webpack 与我的 ASP.NET Core 1.1 应用程序结合使用。我正在使用刚刚发布的 1.1 的 .NET Core 预览版,虽然​​我刚刚升级到 1.1 并且之前使用的是 1.0,但我仍然遇到同样的问题。

以下: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

{
"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();
}

据我所知这应该有效,但我不知道我错过了什么。我感觉我的 project.json 很奇怪。

最佳答案

如果非要我猜的话,我会说您的 Startup.cs 文件顶部没有 using Webpack;。如果您使用的是 Visual Studio,如果您右键单击错误并单击“快速操作和重构...”或按 Ctrl+,它应该会为您添加它。

关于c# - 在 ASP.NET Core 1.1 中使用 Webpack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40315840/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com