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 like to do is have my app display the build number somewhere. Doesn't matter where...but for example in a WebAPI endpoint like /api/buildversion.
Can anyone help with how I can get the TFS build number at runtime? When the app is packaged/published is there any file which contains the build number that I can access from the application?
You can see both the SDK versions and runtime versions with the command dotnet --info .
Build and Release variables can be found in the Microsoft Documentation, but the more useful ones include: $(Build. BuildNumber) - This is the full build number (see above for setting an appropriate format). $(Build.
NET Core is used to create server applications that run on Windows, Linux and Mac. It does not currently support creating desktop applications with a user interface. Developers can write applications and libraries in VB.NET, C# and F# in both runtimes.
Builds and runs the app using the specified framework. The framework must be specified in the project file. Forces all dependencies to be resolved even if the last restore was successful.
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}#"
}
}
There is an easier way than adding more plugins and libraries. If you are using the web/app deploy method, expand the File Transforms & Variables
Assuming you want to update say a build number value in your appsettings.json
Then just update the variables setting in your release definition of VSTS
Super easy. This is more or less the same steps in Octopus IIRC.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With