Create a nuget package and publish it to Azure Devops Repository

1 minute read

So an idea came up. Decorate your C# domain event class with “DomainEvent” attribute. Write a tool that parse the decorated the class and generate markdown file.

So this post is about creating a nuget package for those attribute classes.

Two attributes

// for domain event class
public class DomainEventAttribute : Attribute
    public string TopicName { get; }
    public string Description { get; }

    public DomainEventAttribute(string topicName, string description)
        TopicName = topicName;
        Description = description;

// for property description
public class DomainEventDescriptionAttribute : Attribute
    public string Description { get; }

    public DomainEventDescriptionAttribute(string description)
        Description = description;

Class library project

Create a class library project and put those two above classes. Make it packable with some extra properties.

<Project Sdk="Microsoft.NET.Sdk">

    <Description>Decorator to wrap your service's domain event classes</Description>
    <Authors>Innovation Technology</Authors>
    <Product>Domain Events Package</Product>


Buld and publish

Build and publish on Azure Devops pipeline

name: 0.1$(Rev:.r)
queue: Hosted VS2017
    - master
  buildConfiguration: 'Release'
  packageProject: '**/*Attributes.csproj'
  dotnetCliVersion: '2.2.101'
- script: |
   git clean -d -x -f
  displayName: Clean Sources

- task: DotNetCoreInstaller@0
  displayName: DotNet CLI Installer
    version: $(dotnetCliVersion) 

- task: DotNetCoreCLI@2
  displayName: Build Projects (Release)
    projects: $(packageProject)
    packDirectory: '$(Build.ArtifactStagingDirectory)/nupkgs'
    arguments: '-c $(buildConfiguration) /p:Version=$(Build.BuildNumber) /p:PackageVersion=$(Build.BuildNumber)'

- task: DotNetCoreCLI@2
  displayName: Pack (release)
    command: 'pack'
    configuration: 'release'
    packagesToPack: $(packageProject)
    packDirectory: '$(build.artifactStagingDirectory)/nupkgs'
    nobuild: false
    versioningScheme: 'byBuildNumber'

- task: DotNetCoreCLI@2
  displayName: Publish to Nuget Feed (release)
    command: push
    packagesToPush: '$(Build.ArtifactStagingDirectory)/nupkgs/*.nupkg'
    publishVstsFeed: '<< your feed id>>'