.NET Core App - How to get build number at runtime

后端 未结 3 1072
鱼传尺愫
鱼传尺愫 2021-01-12 14:39

I\'ve got a .NET Core MVC app which is built using TFS online, and published to Azure using the Release management stuff in TFS online. All very nice.

What I\'d lik

3条回答
  •  不要未来只要你来
    2021-01-12 15:26

    The simple way is that you can store the build number in a file (e.g. appsettings.json), then get this data in app code.

    Appsettings.json sample code:

    {
      "ConnectionStrings": {
        "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-WebApplication1-ab933d83-8f4b-4024-9f3c-1aef5339a8f3;Trusted_Connection=True;MultipleActiveResultSets=true"
      },
      "Logging": {
        "IncludeScopes": false,
        "LogLevel": {
          "Default": "Debug",
          "System": "Information",
          "Microsoft": "Information"
        }
      }
      "CodeVersion": {
        "Num": "#{MyBuildNumber}#"
      }
    }
    
    1. Install Replace Tokens extension
    2. Edit your build definition
    3. Click Variables tab and add a variable. (Name: MyBuildNumber, Value:$(Build.BuildNumber))
    4. Add Replace Tokens build step before build step

提交回复
热议问题