Nuget Problems Downloading Scripts

2019-08-21 10:38发布

Ok, this has happened before, I'm not sure what the deal is.

I go to install this nuget package- Microsoft.jQuery.Unobtrusive.Ajax

the package is installed "correctly" both using the command line and the GUI. But there is no scripts added to my project?

I had the same problem with MVC6 Grid. At least there I could hack the scripts in.

I found the actual script on Microsoft's CDN page so I can work around this...just wondering if I'm missing something.

Using Visual Studio 2017 and the Project is a Core 2.0 MVC project if that helps. Thanks.

1条回答
女痞
2楼-- · 2019-08-21 10:47

the package is installed "correctly" both using the command line and the GUI. But there is no scripts added to my project?

Since the usage of NuGet for css/javascript libraries is discouraged. You should use Bower or the npm (Node Package Manager) to add the JavaScript libraries instead of using NuGet. The newer project file formats, PackageReferences, only supports files that are in a contentFiles directory inside the NuGet package.

To use the package Microsoft.jQuery.Unobtrusive.Ajax to the .net core project, you eed to select your MVC project and add a new file to the project root. While in the template manager (Add->New Item...), search for "Bower Configuration File" or "npm Configuration file".

Then edit the file and add your dependency, i.e.

package.json (npm) or bower.json:

  "dependencies": {
    "jquery-ajax-unobtrusive": "3.2.4"
  }

enter image description here

Note: For package.json (npm), once you save, the file will be downloaded in a directory named "node_modules`. This alone won't be enough, as the required files need to be copied over to wwwroot folder, where they can be accessed when the application runs.

For the detailed info, see NPM, BOWER, NUGET, GULP – The Four Horsemen of ASP.NET CORE Apps.

查看更多
登录 后发表回答