{"id":21543846,"url":"https://github.com/radj307/assemblyattribute","last_synced_at":"2025-04-10T04:41:03.491Z","repository":{"id":51969995,"uuid":"493004339","full_name":"radj307/AssemblyAttribute","owner":"radj307","description":"Reusable base attribute designed to be applied to XML tags in csproj files.","archived":false,"fork":false,"pushed_at":"2022-12-22T05:09:17.000Z","size":85,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T05:52:11.146Z","etag":null,"topics":["assembly","assembly-attribute","csharp","xml"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/radj307.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-16T21:25:22.000Z","updated_at":"2024-08-29T03:20:45.000Z","dependencies_parsed_at":"2023-01-30T05:45:42.488Z","dependency_job_id":null,"html_url":"https://github.com/radj307/AssemblyAttribute","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radj307%2FAssemblyAttribute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radj307%2FAssemblyAttribute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radj307%2FAssemblyAttribute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radj307%2FAssemblyAttribute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/radj307","download_url":"https://codeload.github.com/radj307/AssemblyAttribute/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248160629,"owners_count":21057548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assembly","assembly-attribute","csharp","xml"],"created_at":"2024-11-24T05:15:51.165Z","updated_at":"2025-04-10T04:41:03.471Z","avatar_url":"https://github.com/radj307.png","language":"C#","readme":"# AssemblyAttribute\n\nReusable base attribute designed to streamline the process of using auto-versioning scripts in C# project files.  \n\n## Usage\n\nThe `BaseAssemblyAttribute` abstract class accepts any number of strings via `params string[]`, but since it is an abstract class it cannot be used directly.  \nYou can use it to create your own assembly attributes, or just as example code - the implementation is very simple.  \n\n### `ExtendedVersionAttribute`\n\nDerives 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.  \nI 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.\n\n 1.\tAdd the **[AssemblyAttribute](https://www.nuget.org/packages/AssemblyAttribute nuget package)** to your project.\n 2.\tOpen the `.csproj` project file in the editor.  \n    *For .NET Core projects, you can do this by Right-Clicking on the project in the solution explorer \u0026 selecting the **Edit Project File** option.*\n 3. Add an element within the `PropertyGroup` tag to store the version number:  \n    ```csproj\n    \u003cExtendedVersion\u003e\u003c/ExtendedVersion\u003e\n    ```\n 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:  \n    ```csproj\n    \u003cItemGroup\u003e\n      \u003cAssemblyAttribute Include=\"AssemblyAttribute.ExtendedVersion\"\u003e\n        \u003c_Parameter1\u003e$(ExtendedVersion)\u003c/_Parameter1\u003e\n        \u003c!-- \u003c_Parameter2\u003e\u003c/_Parameter2\u003e --\u003e\n      \u003c/AssemblyAttribute\u003e\n    \u003c/ItemGroup\u003e\n    ```\n 5. You can now retrieve the `ExtendedVersionAttribute` with the properties you passed in the csproj file in your code with:  \n    ```csharp\n    System.Reflection.Assembly.GetCallingAssembly().GetCustomAttribute\u003cExtendedVersionAttribute\u003e();\n    //                         ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲\n    //  Adapt as needed to get the assembly that corresponds to your csproj file!\n    ```\n\nNow 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)*:  \n/*```ps1\n[xml]$CONTENT = Get-Content -Path \"\u003cYOUR_CSPROJ_FILE_PATH_HERE\u003e\"\n$CONTENT.Project.PropertyGroup.ExtendedVersion = git describe --tags --abbrev=0\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradj307%2Fassemblyattribute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fradj307%2Fassemblyattribute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradj307%2Fassemblyattribute/lists"}