How to create Nuget package in VS2015? - c#

I have a VS2015 solution with 6 projects in it. I'd like to create a nuget package out of it but:
the project is for internal use only, so I don't want to publish it online
It should include the source code (is it possible?, not a strict requirement)
It should be the final artifact, can I choose a directory where to have such package?
thanks

You can publish nuget in your private host with https://github.com/themotleyfool/Klondike.
you can use nuget Package Explorer to create nuget package. https://github.com/NuGetPackageExplorer/NuGetPackageExplorer

You have multiple options. Either you can use command prompt or Nuget Package Explorer.
In order to publish you can use Nuget official server or private Nuget server. I recommend Nexus Nuget server.
For publish official one, you need to create account and obtain api key.
You can find detailed usage in here.
For including source code, there is no such a thing in official one. Because it aims ready to use artifacts.
You can add your dll, dependencies, extra files such as configs, html etc

Related

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
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?
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.).
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:
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:
Modify the VS Tool you want to update:
3, Prepare the package.
Go to the root directory of the cloned source code repository:
Right click project 'YoutubeTranscriptApi' in Solution Explorer of VS Tool, and click 'Set as Startup Project':
Change the build configuration of 'YoutubeTranscriptApi' to Release:
Right Click project 'YoutubeTranscriptApi' and click Properties:
Select check box 'Produce a package file during build operations' in Package -> General:
Right Your project 'YoutubeTranscriptApi' and click 'Rebuild':
Then the package will be generated with the default package configurations to local path:
You can configure the above local path as the package source in VS Tool:
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:
Finally, I can use the package with no problem:
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);
}
}
}
}

How can I programmatically find a DLL restored by Nuget?

After a user does a dotnet add package <SomePackage>, the DLL will be installed to a path similar to:
C:\Users\USER\.nuget\packages\SomePackage\1.0.2\lib\netstandard2.0\SomePackage.dll
How can I find this path programmatically? I see there's some information in the obj/project.assets.json that I could parse, and also an interesting DependencyContextJsonReader class under the dotnet github organization.
However, there's no documentation or discussions about this that I can find, and I'm not sure if that's because I'm taking the wrong approach.
Some background:
I'm writing a tool that can scaffold C# projects. It uses a combination of the dotnet command line tools, and the Roslyn Workspace APIs to interact with the generated project. I'd now like to allow the user to install Nuget packages into this generated solution. I invoke dotnet add package SomePackage which works fine, and now I'd like to add the DLL to the Roslyn Project object using the AddReferences API, which requires the actual DLL.
I found a way to do this using the nuget client libraries.
Essentially, rather than shelling out to the dotnet add package command, I can use the NuGet client libraries directly from my application to install packages. I then have access to the full path via the PackagePathResolver.GetInstalledPath method.
Martin Björkström's post, Revisiting the NuGet v3 Libraries, goes into much more detail, and a fully working code sample from Martin is available in this gist.

Is there a way to automatically install a specific version of a Nuget Package at build time?

I have some 3rd party DLL's i need migrating into a TFS Nuget Feed, and I haven't been able to find many articles on the internet about installing specific versions of a given Nuget Package at runtime, could anybody link me to some relevant material and/or provide some pointers to this effect?
Ideally this would be done as an MSBuild Target I think?
Thanks in Advance :)
To promote a cleaner development environment and to reduce repository
size, NuGet Package Restore installs all referenced packages before a
project is built. This widely-used feature ensures that all
dependencies are available in a project without requiring those
packages to be stored in source control (see Packages and Source
Control on how to configure your repository to exclude package
binaries).
This should help NuGet Package Restore
One of the topics
MSBuild-integrated restore in Visual Studio, for NuGet 2.6 and
earlier.

Refer assemblies(artifacts) from artifactory in .NET

I'm trying to make my .Net project work with Artifactory. So far I've uploaded the reference assemblies(.dll) files to artifactory using Jenkins. Now to build my solution, I want to refer those uploaded reference assemblies(artifacts) from artifactory, rather than referring them from the local path.
I tried using the MSBuild artifactory plugin, but it has a partial support for Jenkins.
Is there a way to do this?
You can not reference dll directly from Artifactory. To use them as dependencies in your project you have two options :
first one is to download them locally before your build (you can
setup a prebuild step for that)
second one is to create a nuget
package containing these dlls, to upload this nuget package to
Artifactory (this is where the MsBuild Artifactory plugin can help
you) and use it as a nuget dependency within your project where the
nuget feed used by Visual Studio will be configured to reach
Artifactory nuget repository.

Create a NuGet package after a TFS buld and deploy

What is the best way to make a .dll available as a NuGet package in a local environment so that others can download that and use it whenever they want. We use TFS as the CI server and I want NuGet package (with a version number) to be copied to a location in the intranet after every build so that users can pull it when they want. (Do not want to push). I want this to happen from the all the feature branches, any feature branch other than main needs to package this as a beta. Thanks.
Take a look here: https://www.nuget.org/packages/CreateNewNuGetPackageFromProjectAfterEachBuild/
This will build a nuget package whenever you build.

Categories

Resources