Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restoring Typescript Definition Nuget Packages

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:

Install-Package angularjs.TypeScript.DefinitelyTyped -Version 2.0.2

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>

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)

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)

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.

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


1 Answers

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.

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.

Hope this helps.

like image 105
Jurijs Kovzels Avatar answered Dec 04 '25 06:12

Jurijs Kovzels



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!