How can I make a version of a NuGet package set automatically the same as the packed assemblie's version?
You can do this with replacement tokens in the .nuspec file if you use nuget pack YourProject.csproj.
If you run nuget spec in the same directory as your project file (.csproj) you will have a .nuspec file generated with the replacement tokens already defined. The version replacement token in the .nuspec file, as shown below, will tell NuGet to use the assembly version:
<version>$version$</version>
Then you can run nuget pack YourProject.csproj to generate the NuGet package.
If you cannot use nuget pack YourProject.csproj then you would need to write a utility to read the assembly version and then populate the .nuspec file with the version, and then run nuget pack YourNuSpec.nuspec.
Related
I want to import some package through NuGet into my C++ Visual Studio 2019 project(of couse, packages available in C++).
All packakges I tried to install is from "nuget.org" source.
But all package installation fails with following reasons:
Install-Package : Could not install package 'SomePackage'.
You are trying to install this package into a project that targets
'native,Version=v0.0', but the package does not contain any assembly
references or content files that are compatible with that framework.
For more information, contact the package author.
I think it occurs because I trying to install NuGet package in C++ project.
What is "native,Version=v0.0" means? How can I fix it?
We switched to NuGet to manage our packets in Visual Studio 2017, everyathing works fine now but to push the packages you need to first create a nuspec, create a nupkg (NuGet Package) and then push it to our NuGet Server.
All of this commands get some parameters of which some would stay the same and others need to get from the visual studio variables.
Can you recommend any scripting language that would work for this or have any other solutions for this?
Btw im a "newbie".
Can you recommend any scripting language that would work for this or
have any other solutions for this? Btw im a "newbie".
1.Since we can pack packages from xx.csproj, you can use command like nuget pack xx.csproj to create nuget packages. After that, you can use nuget push command to publish them. To push several nuget packages the same time use command like nuget push path\*.nupkg -source .... You can get some help from this link. Note if you've had the same package with same version in server,it won't automatically overwrite it. (And you can include them in a batch file like this)
2.You can try CreateNewNuGetPackageFromProjectAfterEachBuild package, install this package to your project, and it will create packages automatically for you after each build. So you don't need to manually pack them by command.(Works for my C# .net fx project).
3.For .net core projects, if you right-click the project in Solution Explorer, you can find the Pack button. After build your project successfully in VS, use the pack option will automatically package your assembly.
4.Also, assuming you're in a solution with many class library projects and you want to pack them, you can follow this document.For .net framework projects using packagereference format, add the NuGet.Build.Tasks.Pack package to the project dependencies. After that, you can use command like msbuild -t:pack xx.sln to pack all projects whose GeneratePackageOnBuild property is true.
Most of above are about how to pack packages easily. And after you get the output xx.nupkgs, nuget push *.nupkg -Source... can help you do the publish job.
I have a visual studio solution with several projects all specifing their own packages.config.
If I run "nuget restore blablabla.sln", I get e.g. grpc.core\1.11.0 in my packages folder.
If I let Visual Studio do this I will get grpc.core\1.11.0 and Grpc.Core.1.11.0 in my packages folder both with the same contents!?
Why is that?
BR,
Daniel
Nuget packages doubled
According to your description, you should have more than two package resources in your Visual Studio with same nuget package grpc.core\Grpc.Core (Ignore case). As we know, nuget is not case sensitive when searching and restoring packages. So:
Double check the packages grpc.core\1.11.0 and Grpc.Core.1.11.0 are the same except capitalization.
Clean up your \packages folder before restoring the nuget from
Visual Studio.
If you confirm the above, please check if your package feed have the nuget package grpc.core\1.11.0. You can remove it, since it have the same contents as package Grpc.Core.1.11.0 in the default package source nuegt.org.
Hope this helps.
To date, using Visual Studio 2015, NuGet packagas are restored into a solution-specific "packages" folder, which I check in to source control. Our TFS Build server does not have Internet access, so it needs these local copies to successfully build.
I am now trying out Visual Studio 2017, with a .NETStandard Class library, and it no longer makes a local copy of NuGet packages - instead they appear to be stored in %HOMEDRIVE%%HOMEPATH%.nuget\packages. This means they are no longer available on the Build server.
How can I get NuGet to store packages locally?
You should be able to define a RestorePackagesPath property in your .NET Standard (SDK style) project which defines where the NuGet packages should be restored to.
You can use this to tell NuGet to not use the .nuget\packages directory but instead use some other directory relative to your project.
<PropertyGroup>
<RestorePackagesPath>..\path\to\MyPackages</RestorePackagesPath>
</PropertyGroup>
Looking at the NuGet documentation they mention three possible approaches when using a project that uses PackageReferences.
Set the NUGET_PACKAGES environment variable to a different folder.
Create a NuGet.Config file that sets globalPackagesFolder to a different folder.
Specify a different folder with the RestorePackagesPath MSBuild property.
Details
Using Visual Studio 2017
Built NuGet package with NuGet Package Explorer
Placed .nupkg file in local folder on disk
Added folder to Package Sources in Visual Studio
I attempt to install the package using the Visual Studio GUI (Tools > NuGet Package Manager > Manage NuGet Packages for Solution...).
Problem
My package shows up in the list in the GUI, but when I click install, an error message says it can't find the package in the folder I put the .nupkg file in:
Package 'TDDeviceIntegration 1.0.0' is not found in the following primary source(s): 'C:\Users\j.smith\Documents\Visual Studio 2017\LocalNugetRepository\'. Please verify all your online package sources are available (OR) package id, version are specified correctly.
What I've tried
Putting the NuGet Package I've built in several different local folder locations and adding those to the Package Sources, all with the same result (it can't find the package I JUST put there).
I've restarted Visual Studio several times.
I've restarted my computer.
I've cleared my NuGet cache(s) from Visual Studio
Question
How do I diagnose this? How do I fix this? I just want to make sure that the NuGet package works locally before I give it to the rest of the team.
Thanks in advance!
How do I diagnose this? How do I fix this? I just want to make sure that the NuGet package works locally before I give it to the rest of the team.
Just as #orhtej2 comment, you should:
you rename it to TDDeviceIntegration.1.0.0.nupkg? (dot instead of
space between package name and version).
Additional, some info about why dot is really the only allowed package name-version separator.
That because namespace of nuget package follows a pattern similar to namespaces in .NET, using dot notation instead of hyphens.
You can get the source from following document:
Choosing a unique package identifier and setting the version number
Hope this helps.
According to this link from the NuGet GitHub Repository, you can possibly encounter this error when the version of your package is not "normalized", i.e. it's not made up of 4 digits.
Yours has 3 digits, so...
(and the last digit might have to be 0).