How to add .exe file into nuget package - nuget

There is an .exe file I would like to add my nuget package but I can't seem to find the proper way of doing it..
I would like to add the .exe file into the bin\Debug and bin\Release folders..
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>MyApi</id>
<version>1.6</version>
<title>MyApi</title>
<authors>ASIM GUNDUZ</authors>
<owners>ASIM GUNDUZ</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<description>.Net api</description>
<releaseNotes>Hello World</releaseNotes>
<copyright>Copyright 2020</copyright>
<tags>AApi</tags>
</metadata>
<files>
<file src ="bin\Release\MyApi.dll" target="lib"/>
<file src ="Sample_Usage.cs" target="content\AApi\Sample_Usage.cs"/>
</files>
</package>

Related

nuget not installing file in project\bin directory

Working in VS 2019 .NET framework 4.8
For my C# class library project, I ran nuget spec to create a nuspec file for the dll and its dependencies:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>MyId</id>
<version>1.0.0</version>
<title>MyTitle</title>
<authors>Me</authors>
....
<dependencies>
<dependency id="dll1" version="1.0.0" />
<dependency id="dll2" version="2.0.0" />
</dependencies>
</metadata>
</package>
No problems building the nuget package. In my consuming project (MyProject), I installed that package, and after building MyProject, the class library dll and the dependency files are placed in the MyProject\bin directory. Great.
However I need to get another file into directory MyProject\bin, let's call that file MyFile.txt. I first tried using the element:
.....
<dependency id="dll2" version="2.0.0" />
</dependencies>
</metadata>
<files>
<file src="MyFile.txt" target="lib" />
</files>
</package>
No luck. While the file is in the packages\lib folder, it does not get placed in MyProject\bin.
I then removed the element and tried the element within the tag:
.....
<contentFiles>
<files include="MyFile.txt" buildAction="None" copyToOutput="true" flatten="true" />
</contentFiles>
</metadata>
</package>
No luck that way either. Is there a way to accomplish what I need to do? It looks like it may involve having some folders in my class library root folder, but not sure what folders (content?) or how to properly reference them in the nuspec file. Thanks.
Neglected to update this post with the answer I found.
Using the <files><file /></files> logic is what solved it. It involved the use of the target attribute and using the content keyword in the value:
<files>
<file src="content\bin\MyFile.txt" target="content\bin" />
</files>
It's in the documentation, I unfortunately missed that even upon multiple readings. See https://learn.microsoft.com/en-us/nuget/reference/nuspec#dependencies-element

Nuget not copying content

I am having a problem including a file i need in order for the project to work, here is the nuspec file that i have:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>package_name</id>
<version>1.0.1</version>
<title>x Wrapper</title>
<authors>me</authors>
<owners>me</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>package desc.</description>
<releaseNotes>Bugfix to exe not being copied.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags></tags>
<dependencies>
<dependency id="x.Common.Interfaces" version="1.0.0" />
<dependency id="x.Common.Logging" version="1.0.0" />
<dependency id="x.Wrapper.Common" version="1.0.0" />
</dependencies>
</metadata>
<files>
<file src="build\package_name.props" target="build\package_name.props" />
<file src="build\package_name.targets" target="build\package_name.targets" />
<file src="x.Wrapper\x.exe" target="content\x.exe" />
<file src="bin\Debug\package_name.dll" target="lib\net45\package_name.dll" />
</files>
</package>
When package is pushed and installed to nuget server there is only project dll + dependencies dll's but no other files are being copied into the project. Anyone with some more experience with nuget packages has idea on what could be going on ?

Reference nuspec id elsewhere in the nuspec file?

I have a nuspec file defined like so:
<?xml version="1.0"?>
<package>
<metadata>
<id>PSP.Build.Vcs.Svn</id>
</metadata>
<files>
<file src="tools\**\**\**\PSP.Build.Vcs.Svn\Set-BuildNumber.psm1" target="tools" />
</files>
</package>
As you can see the id is "PSP.Build.Vcs.Svn" and that same literal is repeated in the file element. In the interests of DRY, is it possible to reference the id elsewhere in the nuspec file? I'm imagining something like the following (even though this didn't actually work):
<?xml version="1.0"?>
<package>
<metadata>
<id>PSP.Build.Vcs.Svn</id>
</metadata>
<files>
<file src="tools\**\**\**\$(id)\Set-BuildNumber.psm1" target="tools" />
</files>
</package>
I suspect the answer is no, but just thought I'd ask.
TIA
if you have setup your build process such as that the value of $id$ is PSP.Build.Vcs.Svn then you could replace that with $id$.
See http://docs.nuget.org/Create/Nuspec-Reference#replacement-tokens

NuGet - Create a package with projectUrl from command line

Here's the command line I use to create a NuGet package:
nuget.exe pack something.csproj -OutputDirectory "\\some\directory" -Prop Configuration=Release
Is there a way to set the projectUrl element (or maybe any other Metadata element) directly in the command line?
How about something like the following:
nuget pack something.csproj foo.nuspec /p version=1.0.0.0;projectUrl="http://myurl.com/
while nuspec would look like the following:
<?xml version='1.0'?>
<package xmlns='http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd'>
<metadata>
<id>Foo</d>
<version>$version$</version>
<authors>$authors$</authors>
<description>Some description</description>
<language>en-US</language>
<licenseUrl>$licenseUrl$</licenseUrl>
<projectUrl>$projectUrl$</projectUrl>
<iconUrl>$iconUrl$</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<tags>some tags</tags>
<dependencies>
<dependency id='CodeContracts.Unofficial' version='$codeContractsVersion$'/>
</dependencies>
</metadata>
<files>
......
</files>
</package>

Packaging SQL files only using Nuget.exe

Is there a way to package a folder of only .SQL files instead of having to add them to a project using Nuget.exe?
I know you can specify folders inside the nuspec, but what is the process of doing so? I've only been able to make packages from using .net project/applications.
For example, If I create a nuspec inside called Database.nuspec
F:\folder\trunk\Source\Database.nuspec
inside the folder
F:\folder\trunk\Source\Database
and I want to package up my patch scripts folder
F:\folder\trunk\Source\Database\Patch Scripts
and inside that folder I had
F:\folder\trunk\Source\Database\Patch Scripts\2.0
F:\folder\trunk\Source\Database\Patch Scripts\2.1
F:\folder\trunk\Source\Database\Patch Scripts\2.2
Would I need to include these folders inside of my nuspec or is nuget.exe smart enough to package them up for me?
E.G
Update:
Solution 1:
would be to include each folder to the nuspec
<files>
<file src="F:\folder\trunk\Source\Database\*.sql" target="Database" />
<file src="F:\folder\trunk\Source\Database\Patch Scripts\*.sql" target="Database\Patch Scripts\" />
<file src="F:\folder\trunk\Source\Database\Patch Scripts\2.0\*.sql" target="Database\Patch Scripts\2.0" />
</files>
But I have a lot of patch files and it will be quite tedious to write out about 40 into a nuspec, I will update if I find a work around.
Solution 2:
ufuk-haciogullari suggested using
*\*.sql
as the source since they are one level down, and this does what I want, but I need to keep the file structure intact, If i were to just write
<files>
<file src="F:\folder\trunk\Source\Database\*.sql" target="Database" />
<file src="F:\folder\trunk\Source\Database\Patch Scripts\*\*.sql" target="Database\Patch Scripts" />
</files>
it will store all the returns into the target Database\Patch Scripts\ and this isn't the structure I want.
Update:
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>database</id>
<version>1.0.6</version>
<authors>me</authors>
<description>Description</description>
</metadata>
<files>
<file src="F:\folder\trunk\Source\Database\*.sql" target="Database\" />
<file src="F:\folder\trunk\Source\Database\Patch Scripts\**\*.sql" target="Database\Patch Scripts" />
</files>
This packages my solution and stores the files as they were in the previous format.
nuget.exe pack "F:\folder\trunk\Source\Database\database.nuspec" -OutputDirectory F:\NuGetStore
UPDATE:
Coming back to this, if you leave the target blank in it will re-create the same folder structure that is already in place, so you don't need to create directories.
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>database</id>
<version>1.0.6</version>
<authors>me</authors>
<description>Description</description>
</metadata>
<files>
<file src="F:\folder\trunk\Source\Database\*.sql" target="" />
<file src="F:\folder\trunk\Source\Database\Patch Scripts\**\*.sql" target="" />
</files>
This packages my solution and stores the files.
nuget.exe pack "F:\folder\trunk\Source\Database\database.nuspec" -OutputDirectory F:\NuGetStore
You can create a nuspec file and state those files explicitly.
<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MyPackage</id>
<version>1.0.0</version>
<authors>me</authors>
<description>Description</description>
</metadata>
<files>
<file src="*.sql" target="Content\SqlFiles" />
</files>
</package>
Then run pack command on the nuspec file.
NuGet.exe pack MyPackage.nuspec