use*_*000 19 javascript visual-studio nuget
可能是一个愚蠢的问题.我使用包管理器安装了Chart.js.它在解决方案资源管理器中.
但是实际的JS文件在哪里或者如何获取它们?当我安装它时,Git没有检测到任何变化,所以我不确定是否发生了任何事情.
Mat*_*ard 11
Chart.js 2.5.0在其NuGet包中包含一个Content\Scripts目录,其中包含Chart.js和Chart.min.js.根据您使用的项目类型,这些文件可能会也可能不会直接添加到您的项目中.
如果您使用的是包含packages.config文件的.NET Framework项目,那么JavaScript文件将被添加到项目的Scripts文件夹中.
如果您正在使用project.json文件,或者您的项目使用PackageReferences,则不会添加任何内容,因为此类项目仅支持NuGet包内的contentFiles目录中的文件.您的项目看起来像将使用PackageReferences的.NET Core项目.%UserProfile%\.nuget\packages
如果你需要获取javascript文件,Chart.js NuGet包本身将在目录中.
Tseng的回答是建议切换到使用Bower或Node Package Manager来添加JavaScript文件,这似乎是最好的解决方案,而不是使用NuGet,后者没有很好的支持将源文件添加到项目中以获得更新的项目文件格式.
The usage of NuGet for css/javascript libraries is discouraged. For ASP.NET Core you should use the java script / node package managers, bower
andnpm
respectively.
You can use either one. Bower is more focused on browser libraries and css, while NPM is more for server-sided stuff (using node.js). But node.js also contains most (if not all) of the packages bower has, so it's matter of preference.#
For that, you need to select your MVC project and add a new file to the project root. While in the template manager (Add->New File...
), search for "Bower Configuration File" or "npm Configuration file".
Then edit the file and add your dependency, i.e.
package.json (npm)
{
"dependencies:" {
"chart.js": "2.5.0"
}
}
Run Code Online (Sandbox Code Playgroud)
保存后,该文件将下载到名为“node_modules”的目录中。仅此是不够的,因为需要将所需文件复制到 wwwroot 文件夹,在应用程序运行时可以访问这些文件。
为此,您需要使用捆绑器将文件捆绑在一起(应该在默认的 ASP.NET Core 项目模板中)或使用 Gulp 或 Grunt 等任务运行器在构建/发布时运行任务,这将为您完成。请参阅有关 Gulp 示例的 ASP.NET Core 文档。
Bower现在已被弃用一年多了。
归档时间: |
|
查看次数: |
12198 次 |
最近记录: |