Pack Against .csproj File to Change Path

Topics: General
Jan 30, 2014 at 11:46 AM
Edited Jan 30, 2014 at 1:25 PM
Hi, my project has the following structure:
Assets
  Images
    Image1.png
Views
  Home
    Index.cshtml
Package.nuspec
packages.config
I'd like to package the project so that it has the following output:
lib
  ...
content
  Assets
    Editor
      Images
        Image1.png
Notice how I don't wish to package the Views and the Assets are within a sub directory. Here's my current .nuspec file
<?xml version="1.0"?>
<package >
    <metadata>
        <id>$id$</id>
        <title>$title$</title>
        <version>$version$</version>
        <authors>$author$</authors>
        <owners>$author$</owners>
        <licenseUrl>...</licenseUrl>
        <projectUrl>...</projectUrl>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>$description$</description>
        <copyright>Copyright 2014</copyright>
        <tags>Tag 1</tags>
    </metadata>
    <files>
        <file src="Assets\**" target="content\Assets\Editor" />
    </files>
</package>
Now when I say:
NuGet.exe pack Editor.csproj -Build -Properties Configuration=Release
It creates a package with the following content directory:
Assets
  Images
    Image1.png
  Editor
    Images
      Image1.png
Views
  Home
    Index.cshtml
After consulting the documentation the following line had caught me out:
Note that if you specify any files, the conventions are ignored and only the files listed in the .nuspec file are included in the package.
I realized this is only when you execute the nuget pack command against the .nuspec file. While this will solve my problem I like the idea of doing it against the .csproj file so that the tokens are automatically copied and I don't have to maintain the version, name description etc in two places.

I was able to change my NuGet command to:
NuGet.exe pack Editor.csproj -Build -Properties Configuration=Release -Exclude "Views\**"
This now ignores the Views directory but if I say:
NuGet.exe pack Editor.csproj -Build -Properties Configuration=Release -Exclude "Assets\**;Views\**"
Then I get no Assets directory at all. I'd really appreciate it if someone could suggest how I can achieve my desired output. Thanks

Please note that I do not wish to change the build action as I find this tedious and I know when I add Assets/Views later I will accidently forget to change the build action.
Feb 1, 2014 at 12:16 PM
Edited Feb 1, 2014 at 12:17 PM
I've decided that running the NuGet pack command against the .csproj file isn't going to work. However I've come up with the following PowerShell script which overrides the version within the .nuspec file with the one in the assembly:
$fullVersion = [System.Reflection.AssemblyName]::GetAssemblyName("Editor.dll").Version
$version = "{0}.{1}.{2}" -f $fullVersion.Major, $fullVersion.Minor, $fullVersion.Build

NuGet.exe pack Package.nuspec -Version $version
This allows me to keep the version information in one place.