Nuspec files from nested directory - nuget

I have such file structure:
MyProject/MyProject/bin
I am creating Nuget package via nuspec file. So to add bin folder, I have added this command:
<file src="MyProject/MyProject/bin/**" target="bin"/>
But as a result I am receiving this file structure:
bin/MyProject/MyProject/bin
Is there a way to copy files directly into bin folder, without creating nested directories? So my output would be like simple:
bin

Related

How to pack a directory containing static files using nuget.exe?

How to pack a directory containing static files using nuget.exe? If I would have a csproj file I would be able to generate a nuspec necessary to run nuget pack command, but how to do it when I just have a directory of content files?

How to modify Publish Artifact folder $(build.artifactstagingdirectory) prior its zip creation in VSTS Build process?

I defined VSTS build process till Publish Artifact steps. By default, VSTS agent creates 5 files in Publish Artifact location (c:\vsts-agent_work\1\a) including important build file i.e zip folder. When I checked zip folder, I found long path where my build files are located. folder path in zip -
\Content\C_C\vsts-agent\_work\1\s\ABCProject\obj\Release\Package\PackageTmp
I got to know that source of zip file is source directory after looking in _work folder-
C:\vsts-agent\_work\1\s\ABCProject\obj\Release\Package\PackageTmp
I wanted one folder (RDLCReports Folder) in C:\vsts-agent\_work\1\s\CCM2015MVC\obj\Release\Package\PackageTmp directory. I managed to create that folder using copy files task. I did this step before Publish Artifact step.
Problem is when Publish Artifact step is completed, I didn't get that folder in zip file.
below is snapshot of VSTS build process-
below is Publish Artifact location -
Please let me know how can add that folder in zip? and I also want to know which source path VSTS build has considered to make it as zip folder?
The contents in folder (c:\vsts-agent_work\1\a) is created at the Visual Studio Build task step. So that even if you managed to create RDLCReports folder in C:\vsts-agent\_work\1\s\CCM2015MVC\obj\Release\Package\PackageTmp using copy file task. It will not be copied and zipped to c:\vsts-agent_work\1\a again.
There is a workaround to achieve this. If you want to keep the folder structure in the zip file, You can follow below steps:
1,You need to add a Extract file task to extract the zip file in folder $(build.artifactstagingdirectory) to a different folder (eg.$(Agent.BuildDirectory)/Temp)
2, Add the copy file task to create RDLCReports folder inside the extracted folder in $(Agent.BuildDirectory)/Temp
3, Add a Archive files task to archive the files in the folder
$(Agent.BuildDirectory)/Temp where folder RDLCReports is created.
Make sure uncheck option Prepend root folder name to archive paths and check Replace existing archive
(For above example. My test project is named AboutSite and the zip file is AboutSite.zip. And the folder structure is Content\C_C\agent\_work\1\s\AboutSite\AboutSite\obj\Release\netcoreapp2.0\PubTmp\Out. You need to make a little change to the paths and file name according to your project.)
For your project you may find the contents in C:\vsts-agent\_work\1\s\ABCProject\obj\Release\Package\PackageTmp is the same with your zip file. So there is an another workaround is to add copy file task and target this path C:\vsts-agent\_work\1\s\ABCProject\obj\Release\Package\PackageTmp . And then add the archive file task to archive this folder. However this workaround cannot keep the origin file structure.

Is it possible to change where a nuget package adds files to a project?

If I add a nuget package Foo it might add files to the Content folder in my project.
Content
|
- foo.js
- foo.min.js
- foo.map
What if I wanted something like:
Content
|
- Foo
|
- foo.js
- foo.min.js
- foo.map
Most of the other questions I have found are talking about the location of the packages folder - is something like the above possible?
NuGet does not put the files into a Content folder inside your project unless that is the folder you used. You can put the files in any subdirectory inside the project. The jQuery NuGet package puts its files in a Scripts subdirectory, for example, and it has the folder structure inside its NuGet package (.nupkg):
Note that the Content directory here is just tells NuGet that it should put the files in the project directory. It does not add the files into a Content directory but instead adds them inside a Scripts directory inside the project.
By default, the Nuget Package Manager puts all the .js files inside the 'Scripts' folder and .css files inside the 'Content' folder. But if you want to create a subfolder and categorize your packages, you will have to manually do that. Create a sub folder and move the files manually to it.

NuGet.exe package not including empty folders

I have created a nuspec file for my solution. The solution has a few empty folders.
I have downloaded the latest nuget.exe from https://docs.nuget.org/consume/command-line-reference
However when I run my nuget pack command the empty folders are not being included. Looking at the documentation for the pack command, I am interpreting the fact that empty folders are included by default because of this flag:
ExcludeEmptyDirectories: Prevent inclusion of empty directories when building the package.
Unfortunately I am not able to get the pack command to include my empty folders.
My files structure is similar to
Root
Folder1
Folder2
Folder3
Folder1 and Folder2 have content files within them, but Folder3 is empty
My nuspec file defined as follows:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Package_7.2_140526</id>
<version>7.2.140526</version>
<title>Package 7.2 rev 140526</title>
<authors>My Company</authors>
<owners>My Company</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A vanilla website</description>
</metadata>
</package>
I have not included individual files because I want the nuget pack to include everything. While my example is only of 3 folders there are significantly more than than.
This is the nuget command I am running from the command line
nuget pack "c:\Projects\Package 7.2 rev 140526\Packagee 7.2 140526.nuspec" -OutputDirectory c:\Projects -NoPackageAnalysis
When that did not work I tried with the -ExcludeEmptyDirectories flag just incase
nuget pack "c:\Projects\Package 7.2 rev 140526\Packagee 7.2 140526.nuspec" -OutputDirectory c:\Projects -NoPackageAnalysis -ExcludeEmptyDirectories
But it still will not include the empty folder.
What needs to be done to get the nuget pack command to include the empty folders?
Update
I used the Nuget Package Explorer to add the empty folders to the solution and then looked in the modified nuspec file. It appears that the only way to include empty folders within nuget is to have a file entry as
<file src="folder3\_._" target="folder3\_._" />
And then have a postdeploy.ps1 file to delete all the files named "_._"
So it appears that will always have to specify the files.
Ps. I tested it with the following structure
\Folder3\Folder4.
If folder4 is empty then folder3 and folder4 are not created unless you include the "_._" file
But if there is a way to include empty folders without having to resort to _._ file then want to know, especially if the blank folder is nested as it is easy to get excluded
Yeah, it seems this is an issue that has a shady status of whether it is solved or not and how. There are some issues in the Nuget Github about this, but I coulnd't get a clear picture of what is the status.
Summary is there is a parameter for the nuget 'pack' command that is called -ExcludeEmptyDirectories that in reality is supposed to do the opposite of what it is called, but it doesn't work either what I could test.
See
https://github.com/NuGet/Home/issues/3009

Why NuGet Package manager Download/Copy Packages on multiple Locations?

I have Directory Structure like -
Projects
.nuget
NuGet.exe
NuGet.config
NuGet.targets
**packages (I want to download package for different solution HERE ONLY)**
Sources
Applications
App1
App1.sln (Solution File)
**packages (NuGet downloads packages here first then copies to expected folder, WHY??)**
App1 (Porject Directory)
App1.csproj
App2
App2.sln (Solution File)
**packages (NuGet downloads packages here first then copies to expected folder, WHY??)**
App2 (Porject Directory)
App2.csproj
I have referenced .nuget folder in each solution using following code
Project("{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}") = ".nuget", ".nuget", "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx}"
ProjectSection(SolutionItems) = preProject
..\..\..\.nuget\NuGet.Config = ..\..\..\.nuget\NuGet.Config
..\..\..\.nuget\NuGet.exe = ..\..\..\.nuget\NuGet.exe
..\..\..\.nuget\NuGet.targets = ..\..\..\.nuget\NuGet.targets
EndProjectSection
EndProject
In every project file (.csproj), I have referenced common NuGet.targets using,
<Import Project="..\..\..\..\.nuget\NuGet.targets" Condition="Exists('..\..\..\..\.nuget\NuGet.targets')" />
In NuGet.config, I have added following line so that it should (must) copy packages in EXPECTED folder ONLY
<add key="repositoryPath" value="..\packages" />
I have mapped Projects folder with TFS and it asks me to add files on both locations because of above problem
NuGet will look for the NuGet.config file based on the current solution's directory.
So taking your App1 solution if the Projects directory is in c:\Projects then your App1.sln file will be in the c:\Projects\Sources\Applications\App1 directory. Now NuGet will look for the NuGet.config directory in:
c:\Projects\Sources\Applications\App1\.nuget\NuGet.Config
c:\Projects\Sources\Applications\App1\NuGet.Config
c:\Projects\Sources\Applications\NuGet.Config
c:\Projects\Sources\NuGet.Config
c:\Projects\NuGet.Config
c:\NuGet.Config
After this it then looks in machine wide locations but I will ignore these for now.
Looking at your directory structure the Projects.nuget directory will not be checked by NuGet. It is not a parent of any of the solution directories.
I would look at putting a NuGet.Config file with the repositoryPath setting in the Sources directory or the Projects directory (not in the .nuget directory). Or having two NuGet.Config files, one in the App1.nuget directory and one in the App2.nuget directory.