Including files in content without the containing folders

Topics: General
Mar 25, 2013 at 1:01 PM
Hi All,

I'm building a NuGet package from a *.csproj file.
I want to include a file from a different folder.

When I include content file with the exact path, the file is added directly under content folder.
When I use asterisk (**) in the folder path, the entire path is copied into the content folder.

For example, the project is saved in "root\Freebies.CSharp.csproj" and has the project structure

root\
root\Freebies.CSharp
root\Freebies.CSharp\Freebies.CSharp.csproj
root\Freebies.CSharp\Freebies.CSharp.nuspec
root\Build
root\Build\lib
root\Build\lib\Freebies.JavaApp.jar

The command I'm running is
C:\root>.\.nuget\NuGet.exe pack Freebies.CSharp.csproj
I use this "Freebies.CSharp.nuspec":
<?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$</description>
    <releaseNotes>TBC</releaseNotes>
    <copyright>TBC</copyright>
    <tags>TBC</tags>
  </metadata>
  <files>
    <file src="..\Build\lib\Freebies.JavaApp.jar" target="content\lib" />
  </files>
</package>
This all works well, and I get the content folder:
\content\lib\Freebies.JavaApp.jar

When I change the NuSpec file to reference the file:
<files>
    <file src="..\**\lib\Freebies.JavaApp.jar" target="content\lib" />
</files>
The package contains the entire path:
\content\lib\Build\lib\Freebies.JavaApp.jar

I am using TeamCity, and the path has to be relative to allow the package to build both on my computer and on TeamCity.

Any Idea how to get the file directly into the content folder when using relative path with **?

I'd really approcoate the help.

Thanks,
Eyal
Mar 25, 2013 at 6:44 PM
If you have only one file, why do you want to change to ** ?
Mar 27, 2013 at 8:34 AM
Edited Mar 27, 2013 at 8:41 AM
Hi dotnetjunky,

Thanks! your question drove me to research this a bit more.

Actually, there are two Jar files that I want to include.
(and the plot thickens, the Jars have version numbers: Freebies.JavaApp-1.2.0.jar)

The build on TeamCity works well If I include:
  <files>
    <file src="Build\lib\*.jar" target="content\lib" />
  </files>
When running from TeamCity, the current directly is "root" and so "Build\lib*.jar" is valid.


On my computer, the NuGet package does not build with these settings.

When running from my own computer, I'm running from "root" directory as well.
I get this output:
C:\root>.nuget\NuGet.exe pack Freebies.CSharp\Freebies.CSharp.csproj
Attempting to build package from 'Freebies.CSharp.csproj'.
Packing files from 'C:\root\Build\bin\Debug'.
Using 'Freebies.CSharp.nuspec' for metadata.
Could not find a part of the path 
'C:\root\Freebies.CSharp\Build\lib\'.
Looks like NuGet is now looking for the files in:
Freebies.CSharp\Build\lib\
instead of:
Build\lib\

Does NuGet set the current directory to the NuSpec file path?

Thanks,
Eyal
Mar 27, 2013 at 6:31 PM
Yes, from inside the .nuspec file, all relative paths are evaluated against the nuspec file path.