I have a .NET project with the following in its .csproj
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
When I run dotnet restore project-file.csproj I get the following:
Nothing to do. None of the projects specified contain packages to restore.
Why is this? I thought the dotnet cli could work with non Core projects too?
I have nuget packages that are referenced, so I expect the cli to go and download the nuget packages.
dotnet cli works properly with .NET Framework only if the project was created from dotnet new command. If you create project from Visual Studio the structure of .csroj files will be different and you usually cannot run cli commands towards them
Visual Studio only allows you to run nuget commands from nuget console (package manager console) within Visual Studio itself.
If you want to do nuget restore from command line:
Download nuget executable from https://www.nuget.org/downloads
(it is not a installer/package, but actual executable!)
Save it to a folder of your choice and add it to the PATH.
Then, as suggested above: nuget restore solutionname.sln (but this time you don't have to run Visual Studio!)
Related
I have a C# project that makes a lib. I build it just fine with dotnet build. I'd love to publish the dll to ~/.nuget/packages (I am on a Mac, using Rider). Is there a nuget command to query the local repository?
In terms of publishing, I have <GeneratePackageOnBuild>true</GeneratePackageOnBuild> added to the csproj file of the lib. Also <IsPackable>true</IsPackable>, yet nothing is put into ~/.nuget/packages if I do dotnet pack.
dotnet build
dotnet pack
nuget add path/to/<yourProjeName>.nupkg -source ~/.nuget/packages
For Mac, brew install nuget is how you add a version of Nuget to your system. At least one that is different to the nuget built into the dotnet command that has a different syntax.
Then use ls, find, ag an wotnot for ~/.nuget file location
To publish NuGet package to your local repository you can either add the following property.
<PackageOutputPath>PATH_TO_YOUR_LOCAL_REPO</PackageOutputPath>
NOTE: Don't add the property to a csproj file, better adding it to Directory.Build.props and have it in .gitignore so you don't accidentally apply these changes to your CI build if there's any.
another way of doing it is by using dotnet cli pack via o option
dotnet pack -o PATH_TO_YOUR_LOCAL_REPO
We have dozens of solutions in a repository and we're retargeting every project to net472 from net462. Currently our best bet is to open each and every solution in Visual Studio and execute the following command in the Package Manager Console.
Update-Package -Reinstall -IgnoreDependencies
As far as I'm aware, the PM console cannot be used outside Visual Studio, so this method of course is not very efficient, so what I was thinking about is using the nuget.exe tool for this. However at first glance I could not find any equivalent operation or argument set.
The documentation at this moment says the following
For all packages, delete the package folder, then run nuget install.
For a single package, delete the package folder and use nuget install
to reinstall the same one.
So based on this I tried to delete the packages folder and run nuget install for a project, so I expected it to do a re-install. However, while it installed the package indeed (to packages), it does not touch the packages.config (for retargeting).
Is anyone aware of any kind of possible way to automate this process?
How to achieve full NuGet reinstall using nuget.exe CLI?
That command cannot get what you want.
As far as I know, nuget install should be with packages.config file and it will not update the nuget framework version of packages.config file automatically.
So whenever you change the target framework version of your project, using that command will not update the target framework version of the nuget package.
So only update-package -reinstall command under Package Manager Console will update the target framework version of packages.config file.
And also Package Manager Console cannot access multiple solutions so you have to open each solution to run that command.
Although it may be possible to achieve your expectations with PowerShell scripts, but it is too complex so that it is easier to open each solution and then run the command.
As a suggestion,
1) open each solution on VS to run update-package -reinstall command.
2) And migrating from packages.config to PackageReference may be a good choice. In this case, the nuget packages will automatically adapt to the corresponding project target framework version.
Before doing this,you can make a backup of your project.
3) If these all do not meet your requirements, you could suggest a feature on our User Voice Forum to report your desire for automation. After that, you can share the link here and anyone who is interested in it will vote it so that it will get more attention from Microsoft.
All .NET framework projects that use Nuget have a packages.config per project. When I run something like:
nuget update MySolution.sln -Id PackageName -Version 1.2.3
It will update all projects in my solution that use this package to the specified version (1.2.3 in this case)
However, I'm finding that this does NOT work for UWP projects. UWP does not use packages.config and instead put the package references directly into the csproj file. As a result, this is literally what nuget update says when I run it:
Found 2 projects with a packages.config file. (A.csproj, B.csproj)
where A and B are my .NET Framework projects that still have a packages.config file. But this list doesn't include my new UWP projects.
Is there another command for nuget update that will work with UWP projects?
How do I update UWP projects' nuget packages via the CLI?
This is a known issue for the packagereference. At the moment, NuGet CLI does not support automatic package updates to the the new .NET Core .csproj format, you can refer to the below GitHub issue for details:
support for updating references into csproj from commandline(s)
Besides, as test, the workaround using following command line does not work with UWP project
dotnet add package <PackageName> --version <version>
Indeed, currently it is very inconvenient to manage packages outside of Visual Studio for UWP with packagereference.
Hope this helps.
So currently, I am working on a .net core project in Visual Studio 2017. And I am also need to setup CI (Continuous Integration) in VSTS.
Here is my nuget restore step in my build definition
But my build is failing because it couldn't restore any packages. Here is the log of its. It said that "None of the projects in this solution specify any packages". I know that in VS2017 they changed the way nuget packages are being handled.
Anyone has an idea or experience about this?
2017-03-22T20:25:11.9517911Z MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
2017-03-22T20:25:11.9674167Z Nothing to do. None of the projects in this solution specify any packages for NuGet to restore.
2017-03-22T20:25:11.9830425Z ##[section]Finishing: NuGet restore **/*.sln
I don't want to use dotnet restore because Microsoft said that
.NET Core's dotnet restore command doesn't currently support encrypted
credentials. To use VSTS NuGet feeds with dotnet restore, you'll need
to specify a Personal Access Token in plain text.
so I don't want to store my Personal Access Token.
https://www.visualstudio.com/en-us/docs/package/nuget/auth#net-core
You need to use NuGet 4.0.
Download it form the official NuGet site. https://dist.nuget.org/index.html
Put it in a folder on the machine where you have the build agent.
In the Advanced settings of the NuGet restore step set the NuGet version to Custom.
In the Path to NuGet.exe specify the path where you have put the NuGet.exe file. This is the path on the machine where the build agent is running. I tried with a relative path but was not able to get it working so in the end I have put an absolute path. This might be a problem for you if you have multiple agents with different paths so you might need to figure out how to correctly specify the relative path.
The Nuget restore task just includes Nuget.exe 3.3 and 3.5, so there isn’t the option of 4.0. You can check the files in [build agent folder]\tasks\NuGetInstaller\[version]\ node_modules\nuget-task-common\NuGet folder.
You can build a custom build/release task to include nuget.exe 4.0 and use this task instead. More information, you can refer to Add a build task.
On the other hand, you can add Nuget.exe to the source control, then map it to the build agent (Repository tab of build definition) and specify the path with built-in variable (e.g. $(build.sourcesdirectory))
We are using git as source control and we follow the git flow workflow.
We are using Visual Studio 2013
We are using Teamcity v8.1
We have 2 C# solutions. Solution A and solution B. Solution B uses a nuget package that solution A creates.
We are using teamcity as a build server. We have 2 build configurations that creates the Project A nuget package. One build configuration creates a prerelease version of the nuget package, the other one creates the stable version of the nuget package.
The build configuration for creating the prerelease nuget listens on the develop branch. The build configuration for the stable version listens on the master/release/hotfix branches
When we work in the develop branch we use the prerelease version of the nuget package.
But when we create a release branch we want to use the stable version of the nuget package.
What we have tried so far is:
In project B csproj file, we have added an element in the BeforeBuild target that executes nuget.exe to update the prerelease version of the nuget package. That works well, since every time we build project B we will get the latest prerelease version of the nuget package.
But when we are in the release/master/hotfix branch we don't want the prerelease version, we want the stable one.
I've created a powershell script that is executed from project B csproj file in the BeforeBuild target
In the powershell script I can find which git branch we are in, but I haven't found a way to update the nuget package to the latest stable version using nuget.exe. If I could use the nuget cmdlets in the powershell script I could run the update-package with the version flag, but that is not supportered when using nuget.exe
Do you do something similar and how have you solved this?
I while back I also tried to automate updating and installing packages with Powershell. As far as I know there is no way to use the Visual Studio cmdlets outside Visual Studio.
You could do everything yourself. Update packages.config, run nuget update, update csproj file.
It is possible your package has an install.ps1 file. This also uses the Visual Studio cmdlets. For example, the install.ps1 can add a config file to the Visual Studio project and set Copy to Output Directory to Copy if newer.
This means you would have to add these changes to the csproj as well.