生成期间未将 NuGet 包文件复制到项目内容 [英] NuGet package files not being copied to project content during build

查看:59
本文介绍了生成期间未将 NuGet 包文件复制到项目内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 VS2012 Professional 和 NuGet Package Manager 版本 2.2.31210 构建一个 MVC4 Web 应用程序.我的解决方案中有多个项目,所有项目都共享我使用 NuGet 安装的各种包.我的一个项目是一个 MVC4 Web 应用程序,我在其中使用了 bootstrap、jquery UI 等包,所有这些包都是使用 NuGet 安装的.

I am building an MVC4 web application with VS2012 professional with NuGet Package Manager version 2.2.31210. I have multiple projects in my solution, all sharing various packages I installed using NuGet. One of my projects is an MVC4 web application where I am using packages such as bootstrap, jquery UI, etc, all installed using NuGet.

当我从我的存储库克隆我的整个解决方案的新副本并构建我的 MVC4 项目时,包恢复功能似乎正在工作:它在解决方案目录下创建包目录并填充所有版本的包我期待看到.但是,内容文件不会复制到 MVC 应用程序目录中的适当位置.奇怪的是,它确实为内容创建了目录,但并不复制内容文件本身.

When I clone a fresh copy of my entire solution from my repository and build my MVC4 project, the package restore feature seems to be working: it creates the packages directory under the solution direcotry and populates it will all the versions of the packages I expect to see. However, the content files do not get copied to the appropriate places in the MVC app directory. The weird thing is that it does create directories for the content, but does not copy the content files themselves.

例如,我正在使用出现在包/Twitter.Bootstrap.2.2.2 中的 Twitter Bootstrap 包.在 MVC 项目中,在 Content 目录中创建了一个名为 bootstrap 的目录(包含 css、img 和 js 目录).但是,不会将 css 或 js 文件复制到这些目录中!

For example, I am using the Twitter Bootstrap package which appears in the packages/Twitter.Bootstrap.2.2.2. In the MVC project a directory called bootstrap (containing css, img, and js directories) gets created in the Content directory. But, no css or js files are copied into those directories!

有没有人知道我必须说出什么魔法咒语才能让构建从 NuGet 包目录复制这些内容文件?

Does anyone have a clue what magic incantation I must utter to get the build to copy these content files from the NuGet packages directory?

推荐答案

这是我们都遇到的一个非常普遍的问题.我已经创建了一个 MSBuild 任务 NugetContentRestoreTask,它将为您执行此操作.在包管理器控制台中运行以下命令:

This is a very common issue we are all having. I've created an MSBuild Task NugetContentRestoreTask that will do this trick for you. Run the following command in the Package Manager Console:

    PM> Install-Package MSBuild.NugetContentRestore

剩下的唯一事情就是从您的 BeforeBuild 目标中调用它,如下所示:

The only thing left is to call it from your BeforeBuild Target with something like this:

    <Target Name="BeforeBuild">
      <NugetContentRestoreTask SolutionDir="$(SolutionDir)" ProjectDir="$(ProjectDir)" />
    </Target>

您可以查看源代码库并在nuget.org

此 nuget 仅包含默认值文件夹 scriptsimagesfontscontent,它不是递归目录包含.对于其他内容子文件夹 - 您必须分配属性 AdditionalFolders.

This nuget only includes the default folders scripts, images, fonts, and content, it is not a recursive directory includes. For additional content subfolders - you must assign the property AdditionalFolders.

    <Target Name="BeforeBuild">
        <NugetContentRestoreTask SolutionDir="$(SolutionDir)" ProjectDir="$(ProjectDir)" 
              AdditionalFolders="less;sass;common" />
    </Target>

这篇关于生成期间未将 NuGet 包文件复制到项目内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆