ฉันให้คำตอบคุณสองข้อ npmรวมกับเครื่องมืออื่น ๆ มีประสิทธิภาพ แต่ต้องทำงานในการตั้งค่า หากคุณต้องการดาวน์โหลดไลบรารีบางส่วนคุณอาจต้องการใช้Library Managerแทน (เผยแพร่ใน Visual Studio 15.8)
NPM (ขั้นสูง)
ขั้นแรกให้เพิ่มpackage.jsonในรูทของโปรเจ็กต์ของคุณ เพิ่มเนื้อหาต่อไปนี้:
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"devDependencies": {
"gulp": "3.9.1",
"del": "3.0.0"
},
"dependencies": {
"jquery": "3.3.1",
"jquery-validation": "1.17.0",
"jquery-validation-unobtrusive": "3.2.10",
"bootstrap": "3.3.7"
}
}
สิ่งนี้จะทำให้ NPM ดาวน์โหลด Bootstrap, JQuery และไลบรารีอื่น ๆ ที่ใช้ในโปรเจ็กต์หลักของ asp.net ใหม่ไปยังโฟลเดอร์ชื่อ node_modules ขั้นตอนต่อไปคือการคัดลอกไฟล์ไปยังตำแหน่งที่เหมาะสม ในการทำเช่นนี้เราจะใช้ gulp ซึ่งดาวน์โหลดโดย NPM แล้วเพิ่มไฟล์ใหม่ในรากของคุณโครงการชื่อgulpfile.js เพิ่มเนื้อหาต่อไปนี้:
/// <binding AfterBuild='default' Clean='clean' />
/*
This file is the main entry point for defining Gulp tasks and using Gulp plugins.
Click here to learn more. http://go.microsoft.com/fwlink/?LinkId=518007
*/
var gulp = require('gulp');
var del = require('del');
var nodeRoot = './node_modules/';
var targetPath = './wwwroot/lib/';
gulp.task('clean', function () {
return del([targetPath + '/**/*']);
});
gulp.task('default', function () {
gulp.src(nodeRoot + "bootstrap/dist/js/*").pipe(gulp.dest(targetPath + "/bootstrap/dist/js"));
gulp.src(nodeRoot + "bootstrap/dist/css/*").pipe(gulp.dest(targetPath + "/bootstrap/dist/css"));
gulp.src(nodeRoot + "bootstrap/dist/fonts/*").pipe(gulp.dest(targetPath + "/bootstrap/dist/fonts"));
gulp.src(nodeRoot + "jquery/dist/jquery.js").pipe(gulp.dest(targetPath + "/jquery/dist"));
gulp.src(nodeRoot + "jquery/dist/jquery.min.js").pipe(gulp.dest(targetPath + "/jquery/dist"));
gulp.src(nodeRoot + "jquery/dist/jquery.min.map").pipe(gulp.dest(targetPath + "/jquery/dist"));
gulp.src(nodeRoot + "jquery-validation/dist/*.js").pipe(gulp.dest(targetPath + "/jquery-validation/dist"));
gulp.src(nodeRoot + "jquery-validation-unobtrusive/dist/*.js").pipe(gulp.dest(targetPath + "/jquery-validation-unobtrusive"));
});
ไฟล์นี้มีโค้ด JavaScript ที่ดำเนินการเมื่อสร้างและล้างโปรเจ็กต์ มันจะคัดลอกไฟล์ที่จำเป็นทั้งหมดไปยังlib2 ( ไม่ใช่ lib - คุณสามารถเปลี่ยนสิ่งนี้ได้อย่างง่ายดาย ) ฉันใช้โครงสร้างเดียวกันกับในโปรเจ็กต์ใหม่ แต่เปลี่ยนไฟล์ไปยังตำแหน่งอื่นได้ง่าย หากคุณย้ายไฟล์ตรวจสอบให้แน่ใจว่าคุณได้อัปเดต_Layout.cshtmlด้วย โปรดสังเกตว่าไฟล์ทั้งหมดในไดเร็กทอรี lib2 จะถูกลบออกเมื่อโปรเจ็กต์ถูกล้าง
หากคุณคลิกขวาที่gulpfile.jsคุณสามารถเลือกงานวิ่ง Explorer ที่ จากที่นี่คุณสามารถเรียกใช้อึกด้วยตนเองเพื่อคัดลอกหรือล้างไฟล์
Gulp อาจมีประโยชน์สำหรับงานอื่น ๆ เช่น minify JavaScript และ CSS-files:
https://docs.microsoft.com/en-us/aspnet/core/client-side/using-gulp?view=aspnetcore-2.1
ผู้จัดการห้องสมุด (ง่าย)
คลิกขวาที่คุณโครงการและเลือกจัดการลูกค้าด้านห้องสมุด ขณะนี้ไฟล์libman.jsonเปิดอยู่ ในไฟล์นี้คุณระบุว่าจะใช้ไลบรารีและไฟล์ใดและควรจัดเก็บไว้ที่ใดในเครื่อง ง่ายจริงๆ! ไฟล์ต่อไปนี้คัดลอกไลบรารีดีฟอลต์ที่ใช้เมื่อสร้างโปรเจ็กต์ ASP.NET Core 2.1 ใหม่:
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": [
{
"library": "jquery@3.3.1",
"files": [ "jquery.js", "jquery.min.map", "jquery.min.js" ],
"destination": "wwwroot/lib/jquery/dist/"
},
{
"library": "jquery-validate@1.17.0",
"files": [ "additional-methods.js", "additional-methods.min.js", "jquery.validate.js", "jquery.validate.min.js" ],
"destination": "wwwroot/lib/jquery-validation/dist/"
},
{
"library": "jquery-validation-unobtrusive@3.2.10",
"files": [ "jquery.validate.unobtrusive.js", "jquery.validate.unobtrusive.min.js" ],
"destination": "wwwroot/lib/jquery-validation-unobtrusive/"
},
{
"library": "twitter-bootstrap@3.3.7",
"files": [
"css/bootstrap.css",
"css/bootstrap.css.map",
"css/bootstrap.min.css",
"css/bootstrap.min.css.map",
"css/bootstrap-theme.css",
"css/bootstrap-theme.css.map",
"css/bootstrap-theme.min.css",
"css/bootstrap-theme.min.css.map",
"fonts/glyphicons-halflings-regular.eot",
"fonts/glyphicons-halflings-regular.svg",
"fonts/glyphicons-halflings-regular.ttf",
"fonts/glyphicons-halflings-regular.woff",
"fonts/glyphicons-halflings-regular.woff2",
"js/bootstrap.js",
"js/bootstrap.min.js",
"js/npm.js"
],
"destination": "wwwroot/lib/bootstrap/dist"
},
{
"library": "list.js@1.5.0",
"files": [ "list.js", "list.min.js" ],
"destination": "wwwroot/lib/listjs"
}
]
}
หากคุณย้ายไฟล์ตรวจสอบให้แน่ใจว่าคุณได้อัปเดต_Layout.cshtmlด้วย