0

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
Chris White
  • 233
  • 2
  • 13

1 Answers1

0

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.

Community
  • 1
  • 1
Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • I think you misunderstood slightly. The 'Dependencies:' under the package metadata is empty (No Dependencies), but I don't want this. I want the dependencies metadata to be populated/updated automatically. – Chris White Jun 11 '18 at 08:35
  • @ChrisWhite, Thanks for your reply. You want the referenced project to be be populated/updated **automatically** in the node in the `.nuspec` file, like: ` `, Am I right? – Leo Liu Jun 11 '18 at 08:40
  • No just project dependencies, for example: `` Instead of me manually updating the `.nuspec` file each time I add a new 3rd party library, I would like it to happen automatically. – Chris White Jun 11 '18 at 08:47
  • @ChrisWhite, Got it, I will check if I can achieve it and will let you know as soon as possible. – Leo Liu Jun 11 '18 at 08:50
  • 2
    @ChrisWhite, After a long investigation, I am afraid you have to manually update the dependencies in the `.nuspec` file, since pack the .csproj file not the best option for you. Or you can pack the .csproj file then open the package with nuget package exlporer, edit the nuget package for bin folder. – Leo Liu Jun 11 '18 at 09:59
  • Ok, thanks very much for your time. I've not tried using the Nuget Package Explorer, I will give that a go. Thank you. – Chris White Jun 11 '18 at 10:09