Search code examples
c#visual-studionugetnuget-packagelibraries

How to install this NuGet package if i don't see it?


I want to download this https://github.com/BobLd/youtube-transcript-api-sharp, but i really can't, it's have a strange README, can anyone help?

I tried commands from README and finding this NugetPackage

UPD: Here's info what to do if u have git rep of library u need but it didn't publish to nuget store, thanks to Bowman Zhu-MSFT


Solution

  • I think you may not have a good understanding of some features in Visual Studio and the concepts related to Nuget packages. Below I will provide a specific step as simple as possible based on the source code you provided.

    How to install this NuGet package if I don't see it?

    I think what you said can't be seen means that you can't find it in the nuget gallery, right?

    enter image description here

    The Nuget Gallery is the nuget source of the default configuration of the nuget management of VS Tools (if you just download a VS and start, then this is the source), and it is also the central package repository of the NuGet package manager officially maintained by Microsoft.

    But nuget package repository doesn't only have one choice in VS Tools. VS Tools not only supports Microsoft's official package repository, you can use third-party package repository or even local package repository(local folders).

    The following contents will tell you how to generate a package based on the source code to local repository and make it visable in VS Tools as usual.


    1, Git clone the repository.

    git clone https://github.com/BobLd/youtube-transcript-api-sharp.git

    If you didn't do this step before or don't have experience on this, you need first download Git via this: Git download. And then find out where is the git command exe, configure it to Path of system environment variables(This step will make you be able to use the git command in any where in your system.).

    enter image description here

    enter image description here

    2, Install the VS Tools(I installed VS2022 community 17.4.4), and prepare .net 5 when install.

    The code you provided is based on .net 5:

    enter image description here

    This is why you need to prepare .net 5.

    If you doesn't install before, you can follow below steps to install .net 5:

    Search and click in Visual Studio Installer:

    enter image description here

    Modify the VS Tool you want to update:

    enter image description here

    enter image description here

    3, Prepare the package.

    Go to the root directory of the cloned source code repository:

    enter image description here

    Right click project 'YoutubeTranscriptApi' in Solution Explorer of VS Tool, and click 'Set as Startup Project':

    enter image description here

    Change the build configuration of 'YoutubeTranscriptApi' to Release:

    enter image description here

    Right Click project 'YoutubeTranscriptApi' and click Properties:

    enter image description here

    Select check box 'Produce a package file during build operations' in Package -> General:

    enter image description here

    Right Your project 'YoutubeTranscriptApi' and click 'Rebuild':

    enter image description here

    Then the package will be generated with the default package configurations to local path:

    enter image description here

    You can configure the above local path as the package source in VS Tool:

    enter image description here

    enter image description here

    enter image description here

    the path I configured is:

    C:\Users\Administrator\Desktop\reproduce\cloned_app\youtube-transcript-api-sharp\YoutubeTranscriptApi\bin\Release

    You just need to make sure this path have the package you want.

    You can see the package after change package source in Package management:

    enter image description here


    Finally, I can use the package with no problem:

    enter image description here

    enter image description here

    using System;
    using YoutubeTranscriptApi;
    
    namespace UsePackage
    {
        internal class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Hello World!");
                var videoId = "xxx";
                using (var youTubeTranscriptApi = new YouTubeTranscriptApi())
                {
                    var transcriptItems = youTubeTranscriptApi.GetTranscript(videoId);
                }
    
            }
        }
    }