https://github.com/br-na-pm/BuildVersion
Collect git version information during a project build
https://github.com/br-na-pm/BuildVersion
automation-studio git machine-automation powershell version-control
Last synced: 10 months ago
JSON representation
Collect git version information during a project build
- Host: GitHub
- URL: https://github.com/br-na-pm/BuildVersion
- Owner: br-na-pm
- License: mit
- Created: 2022-03-30T14:56:39.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-30T01:45:12.000Z (over 1 year ago)
- Last Synced: 2024-10-30T03:59:41.200Z (over 1 year ago)
- Topics: automation-studio, git, machine-automation, powershell, version-control
- Language: PowerShell
- Homepage:
- Size: 120 KB
- Stars: 8
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BuildVersion
[](https://www.br-automation.com)


[](https://github.com/br-na-pm/BuildVersion/issues)
[BuildVersion](https://github.com/br-na-pm/BuildVersion#readme) is a software package for [Automation Studio](https://www.br-automation.com/en/products/software/automation-software/automation-studio/) projects to transfer version information to runtime variables during each build.
The package includes a Windows-native [PowerShell](https://learn.microsoft.com/en/powershell/) script to automatically capture version information during the pre-build event.
The script is intended for use with the version control system [git](https://git-scm.com/).
**NOTE:** This is not an official package and is supported by the community. BuildVersion is provided as-in under the [MIT License](https://mit-license.org/) agreement. Source code, documentation, and issues are managed through [GitHub](https://github.com/br-na-pm/BuildVersion).

## Features
- :octocat: Capture git repository information
- :arrow_down: Capture Automation Studio project and build information
- :beginner: Use with and without git
- :file_folder: Initialize local variable
- :earth_americas: Initialize global variable
- :warning: PowerShell script will not throw error in project build by default
- :tv: [mappView widget](https://github.com/br-na-pm/BuildVersionWidget#readme) integration
## Installation
#### 1. Add Package to Project
- [Download](https://github.com/br-na-pm/BuildVersion/releases/latest/download/BuildVersion.zip) and extract
- Logical View -> select project folder -> Toolbox -> Existing Package -> import BuildVersion

#### 2. Create Pre-Build Event
- Configuration View -> active configuration -> right-click CPU object -> Properties
- Build Events -> Configuration Pre-Build Step -> Insert the following
```powershell
PowerShell -ExecutionPolicy ByPass -File $(WIN32_AS_PROJECT_PATH)\Logical\BuildVersion\BuildVersion.ps1 -ProjectPath $(WIN32_AS_PROJECT_PATH) -StudioVersion "$(AS_VERSION)" -UserName "$(AS_USER_NAME)" -ProjectName "$(AS_PROJECT_NAME)" -Configuration "$(AS_CONFIGURATION)" -BuildMode "$(AS_BUILD_MODE)"
```

If the BuildVersion package is placed in subdirectories of Logical, the pre-build event must be updated to reflect the subdirectories.
For example, if the BuildVersion package is placed in a `Tools` subdirectory then the `-File` argument must be updated to the following.
```
-File $(WIN32_AS_PROJECT_PATH)\Logical\Tools\BuildVersion\BuildVersion.ps1
```
The Pre-Build Step will have to be set for all desired configurations.
Upon successful installation, users will see BuildVersion messages in the output results when building.

## Errors
> The argument "C:\projects\MyProject\Logical\BuildVersion\BuildVersion.ps1" to the -File parameter does not exist.
- Possible cause: The pre-build event was created but the BuildVersion package was not added to the project.
- *Remedy*: Follow the [installation](#installation) instructions to add existing package to the project.
- Possible cause: The pre-build event created but does not point to the BuildVersion package.
- *Remedy*: Update the [pre-build field's](#2-create-pre-build-event) script path `$(WIN32_AS_PROJECT_PATH)\Logical\BuildVersion\BuildVersion.ps1` to match the path in the project
> Object "C:\projects\MyProject\Logical\BuildVersion\BuildVer\Variable.var" doesn't exist.
- Possible cause: The BuildVersion package was added to the project, but the pre-build event was not created.
- *Remedy*: Follow the [installation](#2-create-pre-build-event) instructions to create the pre-build event.
- Possible cause: The local task was renamed and the PowerShell script cannot find it.
- *Remedy*: Update the PowerShell script's `$ProgramName` parameter (default `"BuildVer"`) to match the task name in the project.
> BuildVersion: Git in not installed or unavailable in PATH environment
> BuildVersion: Please install git (git-scm.com) with recommended options for PATH
- Possible cause: Using the git client Sourcetree with the embedded git preference.
- *Remedy*: Installing Sourcetree before installing git causes Sourcetree to default to its embedded git option. Sourcetree's embedded git is not available in the PATH environment. [Install git separately](https://git-scm.com/) with default installer options to add git to the PATH environment.
## Developers
The [PowerShell script](https://github.com/br-na-pm/BuildVersion/blob/dd9dd64a9b23b1f31e800e7619e68b56a351374e/BuildVersion.ps1#L16) offers several optional [switch parameters](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.4#switch-parameters).
`-ErrorOnRepository`
Create a build error if git is not installed of the project path does not exist within a git repository.
`-ErrorOnChange`
Create a build error if the git repository shows uncommited changes.
`-ErrorOnInitialization`
Create a build error if neither the local variable or global variable was updated with build information.
`-PrintDebug`
Print all debug messages to the output results.
To run multiple commands in the pre-build event, use the follow syntax.
```powershell
&
```
## Build
Building a project with this package may result in warnings for additional files.

In Automation Studio 4.11+, it is possible to add specific filters to warnings 9232 and 9233. Navigate to Configuration View, right-click the PLC object and select properties, chose the Build tab, and add the follow text to the "Objects ignored for build warnings 9232 and 9233" field. The filters are case sensitive.
```
*README*;*LICENSE*;.git;.gitignore;.github
```
Prior to Automation Studio 4.11, it is possible to suppress *all* build warnings regarding additional files by using `-W 9232 9233` in the "Additional build options" field.