dotnet add package AssemblyAttribute --version 1.0.2
NuGet\Install-Package AssemblyAttribute -Version 1.0.2
<PackageReference Include="AssemblyAttribute" Version="1.0.2" />
paket add AssemblyAttribute --version 1.0.2
#r "nuget: AssemblyAttribute, 1.0.2"
// 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
Reusable base attribute designed to streamline the process of using auto-versioning scripts in C# project files.
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.
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
+ via the
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.
- Add the AssemblyAttribute(https://www.nuget.org/packages/AssemblyAttribute nuget package) to your project.
- Open the
.csprojproject 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.
- Add an element within the
PropertyGrouptag to store the version number:
- Add a new
ItemGroupelement within the
Projecttag to add the attribute to that assembly, and pass in the value of the
PropertyGroupvariable from the previous step:
<ItemGroup> <AssemblyAttribute Include="AssemblyAttribute.ExtendedVersion"> <_Parameter1>$(ExtendedVersion)</_Parameter1> </AssemblyAttribute> </ItemGroup>
- You can now retrieve the
ExtendedVersionAttributewith 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||Versions 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.|
|.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.|
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on AssemblyAttribute:
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.
WPF behavior that updates data bindings on a timer, entirely from XAML.
This package is not used by any popular GitHub repositories.