1

I have created following class which is a definition of custom attribute:

using System;

namespace Gucu112.ConfigurationHelper.Properties
{
    [AttributeUsage(AttributeTargets.Assembly)]
    public sealed class AssemblyReleaseNotesAttribute : Attribute
    {
        public AssemblyReleaseNotesAttribute(string releaseNotes) : base()
        {
            ReleaseNotes = releaseNotes;
        }

        public string ReleaseNotes { get; }
    }
}

Then I have defined this custom attribute in my AssemblyInfo.cs file:

(...)
[assembly: AssemblyReleaseNotes("Example release notes.")]
(...)

What I would like to do is use the attribute as variable in my *.nuspec file (as described for some other assembly attributes here):

<?xml version="1.0"?>
<package>
    <metadata>
        <id>$id$</id>
        (...)
        <description>$description$</description>
        <releaseNotes>$releaseNotes$</releaseNotes>
        (...)
    </metadata>
</package>

However, after pushing the package to the NuGet gallery I cannot see content of my custom attribute. Is there any way to make it works? Thank you in advance for you help.

Gucu112
  • 877
  • 10
  • 12
  • I don't think you can without creating your own .nuspec generator. You can see how they do it [here](https://learn.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio-net-framework) under "Generate the Initial Manifest" where they show a sample .nuspec file. They put the release notes directly in the file. – itsme86 Aug 08 '18 at 15:50
  • 1
    While you can add custom metadata to the package definition, you can't make NuGet take that value dynamically from your attribute, since NuGet doesn't know about it. You can still use a replace value, but such a value would have to be passed explicitly to `nuget pack -properties`. Conceivably you could somehow make your build take the value from that attribute, but if that's even possible it doesn't sound like it would be easy -- ultimately you'd probably be better off not using an assembly attribute for that. – Jeroen Mostert Aug 08 '18 at 15:53
  • Thank you for your comments. I was hoping that it will be easy to do, unfortunately it is not :( – Gucu112 Aug 08 '18 at 21:14

0 Answers0