0
votes

When I nuget pack a web project I want to specify custom unpack locations for content and maintain project dependency metadata.

Given the following manually created example nuspec file:

<?xml version="1.0"?>
<package>
<metadata>
    <id>Web.MyApp</id>
    <version>1.0</version>
    <title>Web.MyApp</title>
    <authors>Chris</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Nuget package containing files for Web.MyApp</description>
    <releaseNotes>release notes</releaseNotes>
    <copyright>Copyright Chris 2017</copyright>
    <tags />
    <dependencies />
</metadata>
<files>
    <file src="bin\**\*.*" target="bin" />
    <file src="views\**\*.*" target="views" />
    <file src="content\" target="content" />
    <file src="scripts\" target="scripts" />
    <file src="Global.asax" target="" />
    <file src="*.config" target="" />
</files>
</package>

This allows me to specify custom unpack locations for bin, content, sprint folders etc but I want the project dependency metadata to be automatically maintained. I don't want to edit the nupsec each time a new dependency is referenced.

As an attempt to resolve this problem I tried to nuget pack the csproj file instead of the nuspec. This maintained the dependency metadata however it made specifying content unpack locations much trickier. I can do the following:

<Content Include="Content\dist\images\brand-logo.svg">
  <Pack>true</Pack>
  <PackagePath>Content\Content\dist</PackagePath>
</Content>

But I couldn't find an elegant solution for the bin folder. I just feel like I'm doing something fundamentally wrong.

So my question is, how can I automatically maintain project dependency metadata when creating a nuget package from a manually created nuspec file?

The pack command I am using:

..\tools\nuget\nuget.exe pack $project + ".nuspec" -IncludeReferencedProjects -    
Properties Configuration=Release -Verbosity quiet -NonInteractive - 
OutputDirectory "$packagedirectory" -Version $buildVersion -Symbols
1

1 Answers

0
votes

Automatically add project dependency metadata to manually created nuspec file

If I understand you correct, I am afraid you have already automatically add project dependency metadata to manually created .nuspec file. You just need to rebuild the project and re-pack the .nuspec file.

When you include the referenced files with wildcard, it will contain the new added project references:

<file src="bin\**\*.*" target="bin" />

Add a new project reference to the project, then re-build the project, the dll file of referenced project will be copied to the \bin folder, So we just need to re-pack the .nuspec file, the referenced project metadata will included in the new created package.

For example, add a Atest reference project to Web.MyApp project, then rebuild the project and re-pack the .nuspec file:

enter image description here

If I misunderstand you, please let me know for free.