Error NU5012 - nuget pack unable to find path (/bin/release/MyProject/bin/release) - nuget

I'm trying to update my nuget package by running the command nuget pack -properties Configuration=Release but this gives me the following error:
Unable to find 'bin/Release/{project-name}/bin/Release'. Mae sure the project has been built
I'm not quite sure why it goes to my Release folder and then continues to go down to another Release folder as this doesn't exist? I'm quite lost here, and I'm not sure what to do.

TL;DR
For the new <Project Sdk="Microsoft.NET.Sdk"> .csproj file format, use dotnet pack to build NuGet packages, even if they target .Net Framework or if the project is multi-targeted. Run this from the directory containing your .csproj (and optionally a .nuspec)
dotnet pack MyProject.csproj -c Release
Note that by default dotnet pack places the output .nupkg in the /bin/Release folder, which is different from the current default folder where older nuget pack placed it.
I would suggest you don't create explicit .nuspec files for the new .csproj formats, since most settings can be set in the "Packages" tab of the new Project format. However, if you do have a .nuspec, then dotnet pack will also combine any .nuspec file matching the project name, allowing for the $ symbol substitution from the version and metadata set in your .csproj.
More Detail
I also experienced this problem - in previous versions, I typically use to use this approach to pack against a .csproj with the .nuspec file of the same name, so that I can use all of the $ tokens like $id$, $version$.
However when attempting this against the newer <Project Sdk="Microsoft.NET.Sdk"> csproj formats:
nuget pack {MyProject}.csproj -Prop Configuration=Release
I received the same error (note the "duplication" of bin\release):
Error NU5012: Unable to find 'bin\Release{MyProject}\bin\Release\'. Make sure the project has been built.
And if I tried packing against a .nuspec containing symbols (NuGet Version: 4.7.1.5393)
nuget pack {MyProject}.nuspec -Prop Configuration=Release
I just get the unhelpful message because nuget isn't able to resolve the $ tokens automatically.
Value cannot be null or an empty string.
Parameter name: value
However, by using dotnet pack instead of nuget
dotnet pack MyProject.csproj -c Release
I get to where I want to be, i.e. a multi-targeted NuGet package with the $ symbols in the .nuspec correctly synchronized from the .csproj (you can verify this by opening up the .nupkg file in e.g. 7zip and examining the final .nuspec file in the package root)

I had the same problem on a multi-targeted project (targetting both net452 and netstandard2.0).
My fix/hack was to add 'TargetFramework=net452' to the list of properties passed to Nuget, and manually adding the netstandard2.0-output to the files-section in the .nuspec-file
Hope someone finds a better solution

Part of Rune's answer (setting TargetFramework=net471 NuGet property)
and using NuGet version 4.9.1 (instruction here: https://stackoverflow.com/a/53614798/1813219)
was a way to go for me.

Actually I just solved the problem on my end. Nuget may not find hidden dll. Here is my solution:
Build the project;
Show all files in visual studio so you can see the hidden files, so that you can see the dll under bin folder;
Right click, open folder in file explorer, then copy it to current folder let them replace/ Or unhidden the files;
Do "Nuget Pack" again.

Related

Nuspec dependencies necessary with PackageReferences

imagine the following situation:
Project A has some NuGet dependencies (ie Project Z, Project Y and Project X). It uses PackageReferences.
Now I want to pack Project A as a .nupkg using a .nuspec file. In a .nuspec file you can declare other NuGet dependencies and they will automatically resolved upon installation.
But is that necessary? I thought the PackageReferences would already resolve them.
When you use PackageReference items in your project, you no longer need a .nuspec file to pack a project. You should be able to pack it with dotnet pack -c Release or msbuild.exe -t:Pack -p:Configuration=Release. (Depending on the project type, you may need to install the NuGet.Build.Tasks.Pack for non-SDK-based .NET Framework projects. .NET Standard, Core, .NET 5+ projects should not need this)
You can still use a .nuspec file though, by specifying a NuspecFile property inside the csproj to instruct the pack task to use it. However, it will override all the settings that NuGet would autogenerate - that's the tradeoff for getting complete control over the .nuspec.
If you pack a project using PackageReference you can have a look at the generated .nuspec file in e.g. obj\Release\FooLib.1.0.0.nuspec.

Nuget .symbols.package upon install doesn't contain pdb's and installs only dll's- VS 2019

I have nuget package with symbols - "Mypackage.symbols.nuget" and has dll and pdb files.
I created a local repository for testing and installed this "Mypackage.symbols.nuget" but after installing i see only dll file present in nuget folder under users directory and pdb is missing.
i tried a tweak by renaming the file manually to "Mypackage.nuget" from "Mypackage.symbols.nuget" and then i tried to install i see both dll and pdb is present after i installed.
Why does not pdb is getting downloaded when i have .symbols.nuget as i need to symbols package with dll and pdb for debugging purpose.
i created nuget package upon csproj property group.
Please suggest.
Mypackage.symbols.nuget is not a package in the form of being installed, and does not have the conditions for being installed. The purpose of this form of package is to publish to nuget.org together with nuget.nupkg. Usually, you should push the Mypackage.symbols.nupkg file into https://nuget.smbsrc.net/.
Before this, you should also push the Mypackage.nupkg into nuget.org(https://api.nuget.org/v3/index.json).
And then input the symbolsource.org(https://nuget.smbsrc.net/) into VS Symbol Server.
In this case, you could install the published Mypackage.nupkg package from the nuget.org and then it will match the related Mypackage.symbols.nupkg on the symbolsource.org so that you can debug the content of the nuget.
You can refer to this document about creating legacy symbol packages(.symbols.nupkg).
=============================================================
All of the above need to push these packages into nuget.org. And in the local, you should use that way. And Mypackage.symbols.nupkg is not an installed package for any projects.
To prove this, you can try these:
1) in my side, I add these node in csproj file to create the symbol package.
<PropertyGroup>
<IncludeSymbols>true</IncludeSymbols>
</PropertyGroup>
Then, config the local path of it into nuget package source. After that, delete the xxx.nupkg directly,
I am sure that nuget package UI cannot find the package under the local path which proves the Mypackage.symbols.nupkg is not an installed nuget package and only be uploaded into the server.
Solution
1) just rename the Mypackage.symbols.nupkg as Mypackage.nupkg since it has the dll and pdb files.
2) use this csproj node to repack your project.
<ItemGroup>
<None Include="$(OutputPath)$(AssemblyName).pdb" Pack="true" PackagePath="lib\$(TargetFramework)"></None>
</ItemGroup>
And the main xxx.nupkg will contain the pdb file.
3) also use this xml node in csproj file:
<PropertyGroup>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
Note: if you want to debug the nuget package locally, you should also pack the resource files into the nupkg file.
See this thread answered by me.
In addition, using Debugging information: Embedded format might be much easier.

Nuget package restore is not working on TFS build server

I followed this blog post and I expected Nuget to just work. It obviously has not. I get errors on all of my third party dll's that I expect NuGet to update automatically:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\
Microsoft.WebApplication.targets (182): Could not copy the file "bin\AutoMapper.dll"
because it was not found.
I have set everything up correctly and I have ensured that the solution has Package restore enabled. If I delete a package locally and build, NuGet restores that package for me.
I am not sure why it is not fuctioning on the build server though.
Any Suggestions?
Try to add NugetRestore Activity to the TFS workfolw
Note:
For Team Foundation Build 2013 on-premises and Visual Studio Team Services (formerly Team Foundation Service), the default Build Process Templates already implement the NuGet Package Restore workflow without any special configuration.
I came across a similar error for log4net nuget package and I solved it in a different way. May be this will be useful to someone some day.
The error from TFS Team Build 2015
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\
Microsoft.WebApplication.targets (182): Could not copy the file "bin\Log4net.dll"
because it was not found.
Cause
The path to the nuget package in the .csproj file for referencing the package in the project cannot be found
Resolution
Edit the .csproj file of the project that has the error.
Look for the node ItemGroupin the .csproj file
You will see the HintPath pointing to a folder, most like the folder contain the name of solution as where it will file the DLL.
Replace the HintPath with <HintPath>..\..\Assemblies\3rd party\log4net\1.2.10.0\2.0\log4net.dll</HintPath>
You nuget package library may not be log4net but a different library. A very easy way would be to be edit the .csproj file of a project in the solution that contains the same nuget package library, copy the reference of the nuget in the ItemGroup and replace in the project that has the error. The reference should start contain ...\Assemblies\3rd party\ ... instead of a physical file location on your machine

Nuget package restore with local feed

I'm trying to get nuget package restore working in a solution that is looking for packages in the regular, public nuget feed and in a local feed located on a shared network drive.
What I've tried so far is enabling nuget package restore on the solution, then editing the Nuget.targets and changing the PackageSources variable, but that doesn't seem to work. Is this possible?
My Nuget.targets file looks like this for the package sources section:
<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<PackageSource Include="https://nuget.org/api/v2/" />
<PackageSource Include="\\mynetworkshare\Development\NugetPackages" />
</ItemGroup>
The error I get on build is "Unable to find version '1.0.0' of package 'MyCustomPackage'. I have verified that the nupkg exists at \\mynetworkshare\Development\NugetPackages\MyCustomPackage.1.0.0.nupkg.
The fix for me was bhuvak's answer plus I had to rename some packages.
I had been creating symbols packages (named similar to MyCustomPackage.1.0.0.symbols.nupkg) and using those from my local package feed folder. However, package restore doesn't seem to pick those up. I had to rename them, removing the .symbols portion of the file name.
After I did that, package restore works great.
Updating the sources in NuGet.targets should work.
Make sure you have added both official NuGet source and local feed explicitly in the targets file.
What error are you noticing ?
We had a similar issue to #evan. We're using the CreateNewNuGetPackageFromProjectAfterEachBuild package to create our NuGet packages on a TFS 2013 build server. We have a local, share based package source and copy the nupkg files from the build output to this share. We found that builds that reference these packages fail because NuGet package restore fails to find the packages in the local source.
Running NuGet from the command line on the build server we get strange behaviour:
nuget.exe list <search-term-for-our-packages> -allversions
always succeeds and lists each version of our packages. However, when we go to a failed build's \src folder and run
nuget.exe restore .\oursolution.sln
we always get:
Unable to find version '1.0.6.341' of package 'our.package.name'.
I tried all sorts of things to resolve this, playing with nuget.config and swapping between versions of nuget.exe but the fix was simply to do with the naming of our nupkg files. By default CreateNewNuGetPackageFromProjectAfterEachBuild names the nupkg that it generates as the package Id plus the build configuration and target. E.g.
our.package.name.1.0.6.341.Release.AnyCPU.nupkg
With this file in our package source nuget list works but nuget restore fails. When I rename the package to
our.package.name.1.0.6.341.nupkg
then nuget list and nuget restore work as expected.
Our fix is simply to modify the config file of CreateNewNuGetPackageFromProjectAfterEachBuild to prevent it including the build configuration and target. But why does nuget restore depend on the package file name whereas nuget list doesn't?

Create nuget package with multiple DLLs

Let's say I have a project with this structure:
MyLibrary\
MyLibrary.sln
MyLibrary.Core\
MyLibrary.Core.csproj
MyLibrary.Extensions\
MyLibrary.Extensions.csproj
MyLibrary.Tests\
MyLibrary.Tests.csproj
I want to create a single NuGet package which packages MyLibrary.Core.dll and MyLibrary.Extensions.dll. I can't seem to figure out how to get NuGet to do this. I've tried building a spec file manually and I've tried building one using "nuget spec MyLibrary.Core.csproj". I've tried adding all of the DLLs to a lib/ folder which I understand to be the convention-based mechanism for adding DLLs to the package. In every case I can get the MyLibary.Core.dll to get into the package but the MyLibrary.Extensions.dll does not end up packaged along with it.
TLDR: What is the best practice for creating a NuGet package with multiple projects / assemblies? Is there a tutorial out there that focuses on this? The tutorials I've found all focus on simple single-project demos.
You'll run NuGet on a single project (or nuspec file), but it supports pointers to other projects via the file element. This element uses the names of your project's References, so you avoid having to a) find the location of other project files, and b) copy files to a particular place as a post-build step.
Supposing you have a nuspec file for MyLibrary.Core.csproj, and it references MyLibrary.Extensions and MyLibrary.Tests such that they end up in the bin directory after a build:
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
...
</metadata>
<files>
<file src="bin\Release\MyLibrary.Extensions.dll" target="lib\net40" />
<file src="bin\Release\MyLibrary.Tests.dll" target="lib\net40" />
</files>
</package>
With this setup, all of your references should end up in the appropriate place in the NuGet package. You still have the hard-coded 'Release' in there, but I'd wager most probably don't distribute NuGet packages of their debug builds anyway.
Did you generate a blank nuspec file with:
nuget spec
If you use that file and then put your dlls in a folder under it named lib, it will package them up.
I had a little trouble with trying to generate a nuspec file from a project or dll. Also, if you manually reference any files in the nuspec file, the conventions are not used. This is probably the problem with nuspecs generated from dlls or projects.
Also, if you are trying to run this from a build script that executes in a different folder, you can tell nuget the location of your .\lib folder via the -BasePath command line:
build\nuget.exe pack nuget\Company.Project.nuspec -BasePath nuget\
Have you tried NuGet Package Explorer? Might be the easiest way:
http://nuget.codeplex.com/releases/view/59864
It seems your problem is the same as this question: Why doesn't nuget include the referenced project when packing?. If so, you can use the -includereferencedprojects option (See http://docs.nuget.org/docs/reference/command-line-reference#Pack_Command).
I recently published a solution for this...
My solution enables automatic creation of NuGet packages when you build the solution where each package can contain multiple assemblies, references to both external NuGets and NuGets created during the same build and even include the source code for debugging.
In your case, all you will need to do is add a new class library project to your solution, reference the projects you want to package, then add a post build event.
You can find an article with a walk-through guide here
and the source code here.
i have some tutorial how i did it with windows and visual studio:
create local folder and call it packages like: c:/packages//lib - important to create another folder in folder call it lib and past there dll.
open nuget package explorer - https://npe.codeplex.com/downloads/get/clickOnce/NuGetPackageExplorer.application
the ui very intuitive just add dll and export it to /lib (for tutorial https://blog.zwezdin.com/2014/building-nuget-packages-with-gui-tool/ it in russian but see on pictures the flow it's about 3 clicks)
it will create nuspec file
open GIT BASH - https://git-for-windows.github.io/ and navigate to: cd c: => cd packages (the path of )
*maybe on windows you will need provide developer options for windows's linux stuff (https://www.howtogeek.com/249966/how-to-install-and-use-the-linux-bash-shell-on-windows-10/)
in GIT BASH enter command: nuget add -source [options]
where: : the full name of nuspec (include .nuspec)
and: the path of folder lib in folder (c:/packages//lib)
after the action ended successfully
in GIT BASH enter another command:
nuget pack .nuspec
not in this folder you have .nupkg file.
How to install a Nuget Package .nupkg file locally? - tutorial how to add it to visual studio.
I had the same problem and I decided to create Nuget which will allow to create other nugets from chosen project.
Package is deployed on the Nuget.org site. After referencing it in the project You need to add nuspeck file to the projects which should generate the projects.
Project with the required nuspeck file
Last thing which should be done by you is invoke command Create-Nuspec in Package Manager. Than the powershell module will take all libraries which are result of the build it will add also the required dependencies and create the nuget in the output directory.
Description about this package is placed here.
I had an issue when adding extra dlls references to a Nuget packages, and testing the package on a sample project, the extra dlls was not being added apparently, no matter the way that I create the Nuget Package.
Then I released that when you uninstall and install again a local Nuget Package with the same version number the changes no take effect, the extra dlls are not added.
So each time you uninstall the package, close visual studio and clear the Nuget Cache,
How to clear NuGet package cache using command line?
Then open again Visual Studio and reinstall the local package to make the change takes effect.
Or make the package version to increase each time to be for Visual Studio to recognize your changes.
For example:
Package-1.0.0
Package-1.0.1
Package-1.0.2
.....
To create a Nuget package from a sample project there are some ways, for example:
Right click to your Visual Studio project and choose the "Pack" option
Then install the nuget package explorer:
https://www.microsoft.com/es-ec/p/nuget-package-explorer/9wzdncrdmdm3?activetab=pivot:overviewtab
And add manually your extra references (dlls files) to your specific targets.
Create a nuget package using a .nuspec file how specified in the documentation:
https://learn.microsoft.com/en-us/nuget/guides/create-packages-for-xamarin
<files>
<file src="Plugin.LoggingLibrary\bin\Release\Plugin.LoggingLibrary.dll" target="lib\netstandard1.4\Plugin.LoggingLibrary.dll" />
<file src="Plugin.LoggingLibrary\bin\Release\Plugin.LoggingLibrary.xml" target="lib\netstandard1.4\Plugin.LoggingLibrary.xml" />
<file src="Plugin.LoggingLibrary.iOS\bin\Release\iOsDependence.dll" target="lib\Xamarin.iOS10\iOsDependence.dll" />
<file src="Plugin.LoggingLibrary.Android\bin\Release\AndroidDependence.dll" target="lib\MonoAndroid10\AndroidDependence.dll" />
</files>
In your files part add your .dll files.
And dont forget, each time you uninstall and install again the nuget package from your local source.
Or you increase the version of the package each time:
Or close Visual Studio, clean the nuget cache and Rebuild your project.
In order to take effect the changes.