Date: September 12 2020
Original Post: https://www.reddit.com/r/dotnet/comments/irancy/standard_targetframework_documentation_dynamic/
You can use shields.io io to create dynamic badges to document what the TargetFramework
is of your .NET project. shields.io supports dynamic query badges in XML
format, and your .csproj
, .fsproj
, or .vbproj
files are XML
files. Here is an example badge from my Towel project:
<a href="https://dotnet.microsoft.com/download" alt=".NET target"><img alt=".NET target" src="https://img.shields.io/badge/dynamic/xml?color=%23512bd4&label=target&query=%2F%2FTargetFramework%5B1%5D&url=https%3A%2F%2Fraw.githubusercontent.com%2FZacharyPatten%2FTowel%2Fmain%2FSources%2FTowel%2FTowel.csproj&logo=.net" title="Go To .NET Download"></a>
How can you make your own badge? Go to shields.io and scroll down to the "dynamic" section, and input the parameters for your project:
data type
:xml
label
:target
data url
: This will be the raw content of your project file. If using GitHub, go to your.csproj
,.fsproj
, or.vbproj
file and click theRaw
button. Then use that URL for this parameter. For Towel, I used: https://raw.githubusercontent.com/ZacharyPatten/Towel/main/Sources/Towel/Towel.csproj].query
://TargetFramework[1]
This is just anXPATH
. You may need to make adjustments if you have multiple targets.color
:#512bd4
Then just click Make Badge
and shields.io will redirect you to your badge. Just copy the URL
that you are redirected to, and use it inside an image markdown or HTML like so:
<a href="https://dotnet.microsoft.com/download" alt=".NET target"><img alt=".NET target" src="YOUR-BADGE-URL" title="Go To .NET Download"></a>
Where "YOUR-BADGE-URL"
is the URL of your badge.
If you want to add the .NET logo to the badge, you can append this on the end of the URL of your badge: &logo=.net
.
Since this is a dynamic queried badge, if you change the target framework on your project, this badge will automatically update with it.
It would be nice if everyone in the .NET community started using standard target framework badges at the top of their README
files. :)