AssemblyAttribute 1.0.2

dotnet add package AssemblyAttribute --version 1.0.2                
NuGet\Install-Package AssemblyAttribute -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AssemblyAttribute" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AssemblyAttribute --version 1.0.2                
#r "nuget: AssemblyAttribute, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AssemblyAttribute as a Cake Addin
#addin nuget:?package=AssemblyAttribute&version=1.0.2

// Install AssemblyAttribute as a Cake Tool
#tool nuget:?package=AssemblyAttribute&version=1.0.2                

AssemblyAttribute

Reusable base attribute designed to streamline the process of using auto-versioning scripts in C# project files.

Usage

The BaseAssemblyAttribute abstract class accepts any number of strings via params string[], but since it is an abstract class it cannot be used directly.
You can use it to create your own assembly attributes, or just as example code - the implementation is very simple.

ExtendedVersionAttribute

Derives from BaseAssemblyAttribute and acts as a method to retrieve the full version string and an array of its segments after being split by all occurrences of ., -, or + via the ExtendedVersionAttribute.Version and ExtendedVersionAttribute.VersionSegments properties, respectively.
I use it with my auto-versioning scripts so I can retrieve the latest git tag in the local repository directly in the code, and that's what this guide will focus on.

  1. Add the AssemblyAttribute(https://www.nuget.org/packages/AssemblyAttribute nuget package) to your project.
  2. Open the .csproj project file in the editor.
    For .NET Core projects, you can do this by Right-Clicking on the project in the solution explorer & selecting the Edit Project File option.
  3. Add an element within the PropertyGroup tag to store the version number:
    <ExtendedVersion></ExtendedVersion>
    
  4. Add a new ItemGroup element within the Project tag to add the attribute to that assembly, and pass in the value of the PropertyGroup variable from the previous step:
    <ItemGroup>
      <AssemblyAttribute Include="AssemblyAttribute.ExtendedVersion">
        <_Parameter1>$(ExtendedVersion)</_Parameter1>
    
      </AssemblyAttribute>
    </ItemGroup>
    
  5. You can now retrieve the ExtendedVersionAttribute with the properties you passed in the csproj file in your code with:
    System.Reflection.Assembly.GetCallingAssembly().GetCustomAttribute<ExtendedVersionAttribute>();
    //                         ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
    //  Adapt as needed to get the assembly that corresponds to your csproj file!
    

Now all you have to do is update the version number in your csproj file before *(re)building the solution somewhere in your build script (This example uses PowerShell):
/
```ps1 [xml]$CONTENT = Get-Content -Path "<YOUR_CSPROJ_FILE_PATH_HERE>" $CONTENT.Project.PropertyGroup.ExtendedVersion = git describe --tags --abbrev=0

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on AssemblyAttribute:

Package Downloads
InputSimulatorEx

Windows Input Simulator fork for .NET Standard 2.1 licensed under MIT. The Windows Input Simulator provides a simple .NET (C#) interface to simulate Keyboard or Mouse input using the Win32 SendInput method. All of the Interop is done for you and there's a simple programming model for sending multiple keystrokes.

Synth.radj307

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 18,279 12/22/2022
1.0.1 696 10/25/2022
0.0.0 681 5/16/2022