DEV Community

Automate the authors of a Nuget package during the build process.

It's very simple.

create a get_authors.sh (Mine is in the root but could also be a folder for build scripts. That's probably where I will put it when I create an example to go with this post.

One line of code in get_authors.sh script file - I tried to put the code in the csproj but because of the percent symbol it was easier to put it in a script.

git log --format='%ae' | grep -v noreply | grep -v outlift | sort -u | tr '\n' ', '
Enter fullscreen mode Exit fullscreen mode

then add this fragment to your csproj file somewhere near the top

    <Target Name="SetAuthors" BeforeTargets="InitializeSourceControlInformation">
        <Exec Command="bash ../get_authors.sh" ConsoleToMSBuild="True" IgnoreExitCode="False">
            <Output PropertyName="Authors" TaskParameter="ConsoleOutput" />
        </Exec>
    </Target>
Enter fullscreen mode Exit fullscreen mode

In the section where the Authors tag is change that to

    <PropertyGroup>
        <Authors>$(Authors)</Authors>
Enter fullscreen mode Exit fullscreen mode

Now the Nuget package Authors value is always up to date.

Easy peasy.

Top comments (0)