I am attempting to configure my project / nuget to auto update a specific nuget package. I am currently using NuGet Version 2.8.* and an using the Automatic Package Restore in Visual Studio strategy. My question is what is the best approach to get NuGet to auto update a project before my app builds? Is what I am trying to do even possible using the Automatic Package Restore strategy? Or do I need to use Command-Line Package Restore wrapped in MSBuild, and specify custom update command and target in the NuGet.targets file?
Not currently possible with Visual Studio tooling. NuGet will not automatically upgrade your package version. You must still do this manually.
Not recommended, but in theory, you could write your own script to query nuget.org for the latest version and then upgrade the version number in packages.config. But this seems like a dangerous approach.
This is an old post but in case someone lands here.
One option could be using pre-build script to run below command:
nuget update configPath packageid
Config path could be either project ".cproj" path, solution (.sln) path, or the package.config file path.
https://learn.microsoft.com/en-us/nuget/tools/cli-ref-update
Note that it seems nuget CLI does not work for .NET Core. For Core you need to use dotnet CLI which has integrated nuget command. But that does not have a separate update command (at the time of this post). You need to use add to update but that command needs an explicit version number.
So a workaround could be calling remove and then add commands.
Related
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);
}
}
}
}
I want to use the Locking dependencies of Nuget (>= 4.9), so I can have automatic package update during dev phase and fixed version during release build.
I enabled the lock file mode, so I now have a packages.lock.json file.
The problem is that when I have floating version of package references in the project file like:
<PackageReference Include="My.Nuget.Package" Version="1.0.*" />
The restore package via Visual Studio Build does not update to new packages version anymore. This behavior appeared after I activated the lock file.
The Microsoft documentation describes the --force-evaluate option with dotnet.exe, that works well but I want to do this directly with an MsBuild option in the csproj.
By checking the NuGet Client code, it seems that a RestoreForceEvaluate option exists in Msbuild NuGet.targets but I have no idea how to use it.
By checking the NuGet Client code, it seems that a RestoreForceEvaluate option exists in Msbuild NuGet.targets but I have no idea how to use it.
I am afraid we could not do that at this moment. According to the nuget wiki,
Enable repeatable package restore using lock file:
There is no such MSBuild equivalent option for option --force-evaluate, so we could not use --force-evaluate directly with an MsBuild option in the csproj.
Hope this helps.
i want to do 'check in' to code uses Nuget package.
what is the the best way to do it?
Do i need to do 'check in' to the package folder?
Is there any way to put the dll's (nuget's dlls) in GAC and add them public key token?
My solution is written in c# .net framework 4.5. TFS version - 2015
thanks!
You should not check in NuGet packages into TFS Version Control. As one of the advantages of using NuGet is that you can use it to avoid checking in binaries to your version control system.
In VS, you can enable package restore:
In TFS, you need to restore NuGet packages during TFS build process by adding a "Nuget Package Restore" task to your build, and the required packages will be downloaded.
More information, refer to this article: https://docs.nuget.org/ndocs/consume-packages/package-restore
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
One of the nuget packages that I am using have a minor problem that I have solved with a pull request. I would however want to include the fix in the build of my own application and I do not want to wait until the fix is released as part of a new version of the nuget package. Which procedure should I now follow to achieve this?
Can I keep my package reference and override the assembly provided by nuget with my own custom version of the assembly? I have tried to just copy the custom assembly to the corresponding location in nuget packages folder but it does not work.
Do I have to remove the nuget package reference and keep the custom library in my version control until the fix gets released?
Especiall when you're working with a team or using a build server, you'll want to not do an in-place replace of the same package version.
You can either add a direct reference to the custom-built assembly (and be sure to version it or to include the source in source control so your colleagues or the build server can compile it themselves), or create a new NuGet package with a higher version number and upgrade to that version.
If you don't have a private NuGet server, you can simply add a (shared) directory as package source for your custom built package, as explained in How to install a Nuget Package .nupkg file locally?.
It may work with the same package version, but then you'll have to remove and reinstall it, and make sure it isn't cached anywhere so the old package won't simply be added again. So you better just change the version number.