NuGet: nuget pack does not include files - nuget

I'm trying to create a NuGet package with the following command:
nuget.exe pack MyBeautiful.nuspec
Which looks like this:
<?xml version="1.0"?>
<package>
<metadata>
...
</metadata>
<files>
<file src="\MyBeautifulApp\bin\Release\*" target="." />
</files>
</package>
With version 3.4.4 of NuGet the generated packaged is 3.8 MB in size but none of my files are included. The NuGet package is empty.
If I try exactly the same with an earlier version of NuGet (3.3.0) my files are included correctly.
Is this a known bug in NuGet 3.4.4 or what am I missing?

Found the issue. This line in the nuspec file:
<file src="\MyBeautifulApp\bin\Release\*" target="." />
Should be:
<file src="\MyBeautifulApp\bin\Release\*" target="" />
So no dot in the target.

Related

Is there a way to create a nuget package consisting multiple projects including some which dont have reference to any other project?

I have following dll's among others in a solution:
Base
Core
Basics
R1
R2
Types
I want to put them all in one single nuget package and upload it to Azure DevOps -> Artifacts. Is this possible ?
Is there a way to create a nuget package consisting multiple projects
including some which dont have reference to any other project?
The short answer is Yes, We could use .nuspec to pack up the assemblies:
Download the nuget.exe.
Create a new project.
Open a cmd and switch path to nuget.exe
Use command line: nuget spec "PathOfProject\TestDemo.csproj"
Open the TestDemo.csproj.nuspec file and modify it and add the assemblies as file; below is my .nuspec file:
<?xml version="1.0"?>
<package>
<metadata>
<id>TestDemo</id>
<version>1.0.0</version>
<authors>Tester</authors>
<owners>Tester</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>TestDemo</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
<files>
<file src="ThePathOfTheDll\*.Base.dll" target="lib\net461" />
<file src="ThePathOfTheDll\*.Core.dll" target="lib\net461" />
<file src="ThePathOfTheDll\*.Basics.dll" target="lib\net461" />
<file src="ThePathOfTheDll\*.R1.dll" target="lib\net461" />
<file src="ThePathOfTheDll\*.R2.dll" target="lib\net461" />
<file src="ThePathOfTheDll\*.Types.dll" target="lib\net461" />
</files>
</package>
Use pack command: nuget pack TestDemo.csproj.nuspec
Besides, if your project is donet project, you can edit your csproj file, add an ItemGroup to include the dlls as below: This will pack the other dlls along with your current project dll in the nuget package:
<ItemGroup>
<Content Include="<path to other dll>">
<Pack>true</Pack>
<PackagePath>lib\$(TargetFramework)</PackagePath>
</Content>
</ItemGroup>

Custom NuGet package not installing in wix project

I generate a NuGet that is is just a number of redist files that I want to use in one of my projects. If I install it in a C# or C++ projects, it works. But when I try to install it in a wixproj project and I get the following message:
Could not install package 'package-1.0.0'. You are trying to install this package into a project that targets 'Unsupported,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 generate the package through a TeamCity task (using NuGet 5.6.0). When trying to generate the package with a NuGet CLI 5.8.1, I get the following warning:
*WARNING: NU5128: Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location. Consult the list of actions below:
Add a dependency group for native0.0 to the nuspec*
Looked at https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu5128, one of the solutions was trying a dependencies group targetFramework, (I used "native0.0") with no success. My nuspec is as follows:
<?xml version="1.0"?>
<package>
<metadata>
<id>package</id>
<version>1.0.0</version>
<authors>package</authors>
<owners>owner</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>my package</description>
<copyright>© 2021 company, Inc</copyright>
<tags>native</tags>
</metadata>
<files>
<file src="downloads\Folder\win32.vs2017\file1.lib" target="lib\native\lib\win32.vs2017\" />
<file src="downloads\Folder\win32.vs2017\file1-debug.lib" target="lib\native\lib\win32.vs2017\" />
<file src="downloads\Folder\Include\**" target="lib\native\include\" />
<file src="build\package.props" target="build\native" />
</files>
</package>
And my props file
<Project>
<PropertyGroup>
<MyVersion>1.0.0</MyVersion>
</PropertyGroup>
</Project>
I can install other NuGet packages into wixprojects, so how I configure mine to work? Thanks.
OK I found it, the issue lies at the line
<file src="build\package.props" target="build\native" />
changing target to "build\" allows the NuGet to be loaded to any project type, included WixProj. Note that the NU5128 warning still exists though, but not an issue for me.

Nuget package delivers an old version of my DLL

I wrote a NuGet package that when my other projects use it they get an old version of one of my DLLs.
I include the newest version of my DLL as a reference in my NuGet project.
Project1.nuspec:
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>CommonLibrary</id>
<version>0.0.1</version>
<authors>It's Me</authors>
<owners>My Company/owners>
<description>Shared Library for Common Code and Wrapper</description>
<dependencies>
<dependency id="NLog" version="4.5.7" />
</dependencies>
</metadata>
<files>
<file src="CommonLibrary.dll" target="lib\net471" />
<file src="HelperCode.dll" target="lib\net471" />
</files>
</package>
The CommonLibrary.dll (the project) my NuGet package delivers the correct latest DLL, but that HelperCode.dll is always an older version.
in my project, I created a directory named: "binaries" and in that directory is the latest version of HelperCode.DLL. I reference that latest version in my project. So the NuGet package should deliver the latest version. I gave it a property of "Copy Local Always"
Any suggestions would be greatly appreciated.

Nuget pack always using Release folder

I'm trying to create a nuget package for a specific build configuration. Let's use Debug as an example. I run the command:
nuget pack path_to_my.nuspec -Properties "Configuration=Debug;"-Verbosity Detailed
It throws me the following error:
Attempting to build package from 'path_to_my.nuspec'.
System.IO.FileNotFoundException: File not found: 'bin\Release\mydll.dll'.
As you can see, it tries to get the dll from bin\Release, and not bin\Debug.
Is it possible to tell nuget to use a different Configuration than Release, or use another path?
It would be necessary to check your nuspec file just in case you have hardcoded the Release path to bin\Release\mydll.dll, which is seems it's the case.
A valid nuspec file would have references to the dll without specifying the environment. Use wildcard to allow for any environment. For example:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MyProject</id>
<authors>iberodev</authors>
<version>1.0.0</version>
<projectUrl>https://www.diegodrivendesign.com/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Sample</description>
</metadata>
<files>
<file src="bin\*\netstandard2.0/ProjectOne.dll" target="lib\netstandard2.0" />
<file src="bin\*\netstandard2.0/ProjectOne.pdb" target="lib\netstandard2.0" />
<file src="bin\*\netstandard2.0/ProjectTwo.pdb" target="lib\netstandard2.0" />
<file src="bin\*\netstandard2.0/ProjectTwo.pdb" target="lib\netstandard2.0" />
</files>
</package>
then you run the nuget pack command to reference your nuspec. Make sure you have compiled the code for the proper environment so that the dll that the nuspec references are available (e.g: dotnet build --configuration Debug)
nuget pack ./*NuGet/*.nuspec -Version 1.0.0 -OutputDirectory foo -Prop Configuration=Debug -Verbosity detailed

Nuget Push (update to package) - showing as new install in package manager

I have a very simple post build script which packages all dlls from my project to a custom nuget server. This works fine, however, when opening package manager from any solution, I see the nuget package as a new install, as opposed to the expected 'update' option.
The nuspec file I am using is:
<?xml version="1.0"?>
<package >
<metadata>
<id>Objects.ForConsumers</id>
<version>1.2015.1111.11</version>
<title>Objects.ForConsumers</title>
<authors>My Firm</authors>
<owners>My Firm</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Objects For Consumers</description>
<releaseNotes></releaseNotes>
<copyright>Copyright 2015</copyright>
<tags>Objects For Consumers</tags>
</metadata>
<files>
<file src="*.dll" target="lib" />
</files>
</package>
The version number is incremented with each build.
The commands are essentially
nuget pack Objects.ForConsumers.nuspec
nuget push Objects.ForConsumers.1.2015.1111.12.nupkg -s http://nuget.myserver.com myApiKey
Can anyone suggest which this is happening?
You have selected the "online" option on the panel/tab on the left. If you select "Updates" and search for your package, you should see the update button.
I finally stumbled over the resolution to this. My nuspec file has the following:
<files>
<file src="*.dll" target="lib" />
</files>
I updated this as follows:
<files>
<file src="*.dll" target="lib" />
<file src="*.dll" target="lib/net40" />
</files>
(Adding in the specific folder for my .net version) And all is working now!
Hope this helps somebody else in the future.