恢复 Typescript 定义 Nuget 包 [英] Restoring Typescript Definition Nuget Packages

查看:23
本文介绍了恢复 Typescript 定义 Nuget 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个新项目,该项目将 Typescript 用于所有客户端代码.我使用了许多纯 JavaScript 库来让它们与我的 Typescript 一起工作.我使用 Nuget 通过以下包管理器命令拉入 *.d.ts 文件.

I'm currently working on a new project that uses Typescript for all client side code. I use a number of pure JavaScript libraries to have them work with my Typescript. I used Nuget to pull in the *.d.ts files via the following package manager commands.

一个示例包管理器命令:

An example package manager command:

安装包 angularjs.TypeScript.DefinitelyTyped -Version 2.0.2

Install-Package angularjs.TypeScript.DefinitelyTyped -Version 2.0.2

这很有效,安装完我所有的 Nuget 包后,在项目目录中创建了一个名为 packages.config 的文件:

This works a treat and after installing all my Nuget packages a file is created called packages.config in the project directory:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="angularjs.TypeScript.DefinitelyTyped" version="2.0.2" targetFramework="net45" />
  <package id="angular-translate.TypeScript.DefinitelyTyped" version="0.9.0" targetFramework="net45" />
  <package id="bootstrap.TypeScript.DefinitelyTyped" version="0.0.9" targetFramework="net45" />
  <package id="jquery.TypeScript.DefinitelyTyped" version="1.4.0" targetFramework="net45" />
</packages>

安装包后,我的 Visual Studios 项目现在具有以下目录:

My Visual Studios project now has the following directories after the packages have been installed:

Scripts\
    typings\
        angularjs\         (contains relivant files)
        angular-translate\ (contains relivant files)
        bootstrap\         (contains relivant files)
        jquery\            (contains relivant files)

现在我的问题是当其他人试图克隆我的存储库时,visual studios 将尝试自动恢复 Nuget 包,但以下列方式安装它们:

Now my problem is when someone else tries to clone my repository visual studios will try and automatically restore the Nuget packages but installs them in the following fashion:

Packages\
   angularjs.TypeScript.DefinitelyTyped.2.0.2\
       Content\
           Scripts\
               typings\
                   angularjs\ (contains relivant files)

   angular-translate.TypeScript.DefinitelyTyped.0.9.0\
       Content\
           Scripts\
               typings\
                   angularjs\ (contains relivant files)

   bootstrap.TypeScript.DefinitelyTyped.0.0.9\
       Content\
           Scripts\
               typings\
                   angularjs\ (contains relivant files)

   jquery.TypeScript.DefinitelyTyped.1.4.0\
       Content\
           Scripts\
               typings\
                   angularjs\ (contains relivant files)

我已经阅读了许多 stackoverflow 线程和 Nuget 文档,但似乎无法真正找到可以在新存储库机器上运行命令的解决方案,它将文件恢复到我的配置在原始机器上.

I have read over a number of stackoverflow threads and the Nuget documentation but can't really seem to find a solution to where I can run a command on the new repo machine and it will restore the files back to the configuration I had on the original machine.

理想情况下,我希望避免编写和 *.bat 文件来将文件结构转换为我想要的方式.

Ideally I would like to avoid having to write and *.bat file that will transform the file structure to the way I want.

推荐答案

我相信您正在经历一种常见的Nuget 误解.这里的问题是(自动)Nuget 还原与安装包不同.Nuget Restore 的目的是下载和解压软件包.它不会还原您的项目或解决方案文件夹的内容.阅读文章以了解有关原因的更多详细信息.有很多人对这种行为感到愤怒,但这是 Nuget 开发人员的选择.

I believe you are experiencing one of common Nuget misconceptions. Problem here is that (Automatic) Nuget Restore is not the same as Install-Package. Aim of Nuget Restore is to download and unpack packages. It will not restore content of your project or solution folders. Read article for more detail on why. There is a lot of people mad about this behavior, but this is the choice of Nuget developers.

在对这个问题的评论中提到了许多解决方案.我个人使用 Install-Package MSBuild.NugetContentRestore 这就是我解决内容文件问题所需的全部内容.

A number of solution is mentioned in comments to this issue. I personally use Install-Package MSBuild.NugetContentRestore which is all I need to resolve content files issue.

希望这会有所帮助.

这篇关于恢复 Typescript 定义 Nuget 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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