Include *.resource.dll in nuget packages - c#

When creating nuget package, I want to include all resources files.
Is it possible without specify one by one with tag in the .nuspec file ?
Maybe with wildcards ?

Just use some form of a wildcard. Here's an example I found.
<?xml version="1.0"?>
<package>
<metadata>...
</metadata>
<files>
<file src="lib\**" target="lib" />
</files>
</package>

Related

Why are the files from the contentFiles folder not getting copied over to the bin folder?

I'm trying to get my sql files from the nuget package to the bin folder of my Application. I was setting up the .nuspec file for it. I can see in the .nuget folder that the sql files are a part of the nuget package but they are not reflected in the bin/Debug folder.
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>Athi</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<copyright>$copyright$</copyright>
<tags>Logger</tags>
<dependencies>
<dependency id="Dapper" version="2.0.123" />
<dependency id="System.Data.SqlClient" version="4.8.3" />
</dependencies>
<contentFiles>
<files include="bin\Release\net6.0\Scripts\*.sql" buildAction="Content" copyToOutput="true" />
</contentFiles>
</metadata>
<files>
<file src="bin\Release\net6.0\Scripts\*.*" target="lib\net6.0\Scripts" />
<file src="bin\Release\net6.0\Scripts\*.*" target="contentFiles\Scripts" />
</files>
</package>
Firstly, according to the docs:
The package project should structure content using the following pattern:
/contentFiles/{codeLanguage}/{TxM}/{any?}
For example:
Language- and framework-agnostic:
/contentFiles/any/any/config.xml
net45 content for all languages
/contentFiles/any/net45/config.xml
C#-specific content for net45 and up
/contentFiles/cs/net45/sample.cs
It doesn't look like you are putting them into the correct directory in your NuGet package.
Secondly, according to the docs, contentFiles is only supported on NuGet 4.0+ with PackageReference. Are you using a high enough version of NuGet? Are you using PackageReference in your project files instead of a packages.config file in your project?
TIP: If you find the documentation is lacking in examples of what you are attempting to do, download some (recently made) real packages from https://nuget.org to locate one that does something similar to what you want and use NuGet Package Explorer to see how the packages are arranged.

How to correctly specify dependency information in nuspec file while creating Nuget package?

I'm trying to create Nuget package from a Visual Studio 2017 class Library first time. It is a .NET Framework 4.6.2 project.
The class library is referencing some other nuget packages, dlls, exes which are in References section under Solution Explorer.
Here are the steps I took after looking at some youtube videos and Microsoft documentation:
Right click project and select Properties.
Build option, set Configuration to Release. Saved and closed project properties.
Opened csproj file and changed Configuration to Release
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
Now build the project in Release mode. I can see dlls under
MyProject\bin\Release and also under MyProject\bin\Debug
Then I create the spec file using
nuget spec
Opened it and made appropriate changes and then
nuget pack MyProject.nuspec
I am getting number of warnings like both for Debug and Release directory:
WARNING: NU5100: The assembly 'bin\Debug\Encryption.dll' is not inside the 'lib' folder and hence it won't be added as a reference when the package is installed into a project. Move it into the 'lib' folder if it needs to be referenced.
although the Class Library (which I am creating Nuget), has a packages.config and has references:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Encryption" version="1.1.0" targetFramework="net462" />
...
...
...
<package id="TeraData" version="16.20.8" targetFramework="net462" />
</packages>
Since I am getting warnings, I tried entering dependency information in the nuspec file. Here is what my nuspec file looks like
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>ProjectTitle</id>
<version>1.0.0</version>
<title>ProjectTitle</title>
<authors>auther name</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>desc of package</description>
<releaseNotes>release notes text</releaseNotes>
<copyright>Copyright info</copyright>
<tags>some tages</tags>
<dependencies>
<dependency id="Encryption" version="1.1.0" />
...
<dependency id="TeraData" version="16.20.8" />
</dependencies>
</metadata>
</package>
But still get same warnings. If you can please provide a sample how dependency info in nuspec should look like, that would really help!
Please advise if I'm missing anything!
I think it's just a problem with the command of your nuget pack method.
We usually do not use nuget pack xxx.nusepc command to pack a nuget package because it cannnot pack the realated dll,pdb files including the main nuget project's dll automatically into the nupkg.
You have to write the whole nuspec node with it. You have to write <files> node in nuspec file to include your main project's dll so that it will remove the warning of missing dependencies. You should not add <references> node additionally.
like:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>ProjectTitle</id>
<version>1.0.0</version>
<title>ProjectTitle</title>
<authors>auther name</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>desc of package</description>
<releaseNotes>release notes text</releaseNotes>
<copyright>Copyright info</copyright>
<tags>some tages</tags>
<dependencies>
<dependency id="Encryption" version="1.1.0" />
...
<dependency id="TeraData" version="16.20.8" />
</dependencies>
</metadata>
<files>
<file src="bin\Release\ProjectTitle.dll" target="lib\net462" />
.....
</files>
</package>
Then, use nuget pack xxx.nuspec -Properties Configuration=Release command to pack it. You should pack the the main project' dll in this way. And if your project refences other assembly dlls or extra exe files.
You should add them:
<file src="bin\Release\extra_assembly.dll" target="lib\net462" />
<file src="bin\Release\extra_exe.exe" target="lib\net462" />
=========================================
However, this function is not very convenient. And we usually do not need them, we usually use this:
nuget pack xxx.csproj
Usually, we use nuget pack xxx.csproj -Properties Configuration=Release to pack without any other node. Before this, you should cd xxx\<project folder>.
use this nuspec file:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>ProjectTitle</id>
<version>1.0.0</version>
<title>ProjectTitle</title>
<authors>auther name</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>desc of package</description>
<releaseNotes>release notes text</releaseNotes>
<copyright>Copyright info</copyright>
<tags>some tages</tags>
<dependencies>
<dependency id="Encryption" version="1.1.0" />
...
<dependency id="TeraData" version="16.20.8" />
</dependencies>
</metadata>
<!--If you have any other referenced assembly dll files or pdb files, exe files, you should add them here.-->
<files>
.....
</files>
</package>
You should not add your main nuget project's dll with <file> node and it will add into your nupkg automatically with that command.
When you create the new release version of your nuget package, first uninstall the old one under your project, then delete all cache files under C:\Users\xxx\.nuget\packages. After that, reinstall the new release one in your new project.
Here is the nuspec file structure using .NET framework which finally worked for me:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>ClasslibProj </id>
<version>1.0.0.0</version>
<title> ClasslibProj</title>
<authors>author(s) name</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>desc</description>
<releaseNotes>release notes</releaseNotes>
<copyright>Copyright # Company name 2021</copyright>
<tags>tags to search </tags>
<references>
<group targetFramework=".NETFramework4.6.2">
<reference file="SomeOtherNugetpackage1.dll"/>
<reference file="anyexecutable.exe"/>
…
<reference file="ClasslibProj.dll"/> //dll you are working with
</group>
</references>
</metadata>
<files>
<file src="bin\Release\SomeNugetOtherpackage1.dll" target="lib\net20"/>
<file src="bin\Release\anyexecutable.exe" target="lib"/>
..
<file src="bin\Release\ClasslibProj.dll" target="lib\net462"/>
</files>
</package>
Build project in Release mode.
use command:
nuget pack ClasslibProj.csproj
As mentioned by Sara Liu, avoid using ClasslibProj.nuspec
or you may use detailed command:
nuget pack ClasslibProj.csproj -Properties Configuration=Release

UWP Class Library NuGet package XamlParseException error

Currently I'm working on an UWP NuGet package for making it easier to create great popups and dialogs.
Currently the project is newborn and doesn't have so much controls but I tried to create a NuGet package for it to be a test for making sure it is all good.
Unless I'm using app with the class library referenced to the sample project all things working well but after downloading the library from NuGet I'm getting XamlParseException error.
I searched a bit and find it out that I should add some xaml, xbf or somethings in the output so I tried to add the following lines to my nuspec.
<files>
<!-- XAML controls -->
<file src="Controls\MessageBoxControls\MessageBoxControl.xaml" target="lib\netcore50\Controls\MessageBoxControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\MessageBoxControls\MessageBoxControl.xbf" target="lib\netcore50\Controls\MessageBoxControls"/>
<file src="Controls\PopupControlControls\PopupControl.xaml" target="lib\netcore50\Controls\PopupControlControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\PopupControlControls\PopupControl.xbf" target="lib\netcore50\Controls\PopupControlControls"/>
<file src="Controls\SlideupPopupControls\SlideupPopup.xaml" target="lib\netcore50\Controls\SlideupPopupControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\SlideupPopupControls\SlideupPopup.xbf" target="lib\netcore50\Controls\SlideupPopupControls"/>
</files>
But still I'm getting same error any idea how to solve it?
I should mention that the project is currently available on Github on the following link
https://github.com/NGame1/UWPPopupToolkit
and the NuGet package also is available here
https://www.nuget.org/packages/UWPPopupToolkit
Simply placing the content files in the lib folder of the nuget package will not automatically copy it into the build output folder, only the dll, pdb and xml files will be added into the output projects automatically.
Since your additional files are not the same type, so you cannot get what you want by your method. So I suggest you could try this:
Solution
1) create a folder called build on your root directory of your project and then add a file called <package_id>.props file.
Note: the file must be named the same as your nuget package so that it will work. For an example, if your nuget project named as UWPPopupToolkit.0.0.1-rc.nupkg, the file must be named as UWPPopupToolkit.props.
2) add these content into the UWPPopupToolkit.props file:
<Project>
<Target Name="OutputExtraFiles" BeforeTargets="Build">
<ItemGroup>
<File Include="$(MSBuildThisFileDirectory)..\File\**\*.*"></File>
</ItemGroup>
<Copy SourceFiles="#(File)" DestinationFiles="$(TargetDir)\%(RecursiveDir)%(Filename)%(Extension)"></Copy>
</Target>
</Project>
3) modify your UWPPopupToolkitSDK.nuspec file like this:
<files>
<!-- XAML controls -->
<file src="Controls\MessageBoxControls\MessageBoxControl.xaml" target="File\Controls\MessageBoxControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\MessageBoxControls\MessageBoxControl.xbf" target="File\Controls\MessageBoxControls"/>
<file src="Controls\PopupControlControls\PopupControl.xaml" target="File\Controls\PopupControlControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\PopupControlControls\PopupControl.xbf" target="File\Controls\PopupControlControls"/>
<file src="Controls\SlideupPopupControls\SlideupPopup.xaml" target="File\Controls\SlideupPopupControls"/>
<file src="bin\Debug\UWPPopupToolkit\Controls\SlideupPopupControls\SlideupPopup.xbf" target="File\Controls\SlideupPopupControls"/>
<file src="build\UWPPopupToolkit.props" target="build" />
</files>
4) then repack your nuget project, before you install the new version of the nuget package, please clean the nuget caches first and also delete the bin, obj or any output folders of your main project.
=================================
Update 1
In my side, clean all nuget caches or delete all cache files under C:\Users\xxx(current user)\.nuget\packages and then install the new version of the nuget package, the target files are output to bin\x86\Debug\Controls,
If I install the new version 0.0.1.5-rc,everything works well. See this:
Not sure if your problem is that the files are missing or you want to put them into bin\x86\Debug\netcore50\Controls.
If your issue is the second, you should modify your UWPPopupToolkit.props,
use this:
<Copy SourceFiles="#(File)" DestinationFiles="$(TargetDir)netcore50\%(RecursiveDir)%(Filename)%(Extension)"></Copy>
After that, delete bin and obj folder and then rebuild your main project again.
Thanks to #Perry Qian-MSFT
Finally, I got able to fix the issue.
adding files like this
<files>
<!-- Dll -->
<file src="bin\Release\UWPPopupToolkit.dll" target="lib\netcore50" />
<!-- Resources -->
<file src="bin\Release\UWPPopupToolkit.pdb" target="lib\netcore50" />
<file src="bin\Release\UWPPopupToolkit.pri" target="lib\netcore50" />
<!-- IntelliSense -->
<file src="bin\Release\UWPPopupToolkit.XML" target="lib\netcore50" />
<!-- XAML control -->
<file src="bin\Release\UWPPopupToolkit\**\*.*" target="lib\netcore50\UWPPopupToolkit" />
<!-- Icon -->
<!--<file src="..\icon.png" target="images\" />-->
</files>
solved the problem.
You can find the result files here: UWPPopupToolkitSDK.nuspec | UWPPopupToolkit.props | UWP Popup Toolkit Github

Nuget Ignore content files copying twice

I am trying to create a nuget package with the following structure:
content/Deploy.
Here is my sample nuspec file:
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description></description>
<copyright></copyright>
</metadata>
<files>
<file src="$OutputPath$" target="content\Deploy" />
</files>
</package>
So basically I copy everything from output directory into content\Deploy. The problem is that nuget pack is also generating lib directory and includes some content files from the project in content root directory. Is there a way to exclude everything except the files I specify?
The only content should be the content inside content/deploy in the generated nuget package. How to achieve that?

nuspec omit dlls to be referenced from the lib folder

I have the following nuspec structure:
lib
net40
mylib.dll
And the following nuspec file
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
...
<references>
<!-- don't want to add a reference to mylib.dll. Doesn't work! -->
</references>
...
</metadata>
<files>
<file src="bin\Release\**\*" target="lib\net40"/>
</files>
</package>
I tried to make an empty references block, but it still adds a reference to mylib.dll. I really want mylib.dll to be in the lib folder, because resharper finds it with ALT + ENTER.
How can I omit the reference but still keep the file in my lib folder?

Categories