Skip to content

Commit 23c7241

Browse files
committed
Merge remote-tracking branch 'upstream/master' into RotationalAcceleration
2 parents db104b4 + ae187bf commit 23c7241

File tree

83 files changed

+1365
-97378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1365
-97378
lines changed

Build/set-version-UnitsNet.Serialization.JsonNet.ps1

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@
4343
" If not provided, a version number will be generated.`n"
4444
}
4545

46-
# Import functions: Set-ProjectVersion, Bump-ProjectVersion
47-
import-module "$PSScriptRoot\set-version.psm1"
46+
# Import functions: Get-NewProjectVersion, Set-ProjectVersion, Invoke-CommitAndTagVersion
47+
Import-Module "$PSScriptRoot\set-version.psm1"
4848

49+
$root = Resolve-Path "$PSScriptRoot\.."
50+
$paramSet = $PsCmdlet.ParameterSetName
51+
$commonPropsFile = "$root\UnitsNet.Serialization.JsonNet\UnitsNet.Serialization.JsonNet.Common.props"
52+
$versionFiles = @($commonPropsFile)
53+
$projectName = "JsonNet"
4954

50-
$root = "$PSScriptRoot\.."
51-
$paramSet = $PsCmdlet.ParameterSetName
52-
$projectPaths = @("$root\UnitsNet.Serialization.JsonNet\UnitsNet.Serialization.JsonNet.Common.props")
53-
$projectName = "JsonNet"
55+
# Use UnitsNet.Common.props version as base if bumping major/minor/patch
56+
$newVersion = Get-NewProjectVersion $commonPropsFile $paramSet $setVersion $bumpVersion
5457

55-
Set-ProjectVersionAndCommit $projectName $projectPaths $paramSet $setVersion $bumpVersion
58+
Set-ProjectVersion $commonPropsFile $newVersion
59+
Invoke-CommitAndTagVersion $projectName $versionFiles $newVersion

Build/set-version-UnitsNet.ps1

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
<# .SYNOPSIS
22
Updates the version of all UnitsNet core projects.
33
.DESCRIPTION
4-
Updates the <Version> property of the .csproj project files.
4+
Updates the <Version> property of the .csproj project files and versions of AssemblyInfo.cs files.
55
.PARAMETER set
66
Set new version
77
.PARAMETER bump
88
Bump major, minor, patch or semver suffix number. Only one can be specified at a time, and bumping one part will reset all the lesser parts.
99
.EXAMPLE
1010
Set new version.
11-
-v 2.3.4-beta3: 1.0.0 => 2.3.4-beta3
11+
-version 2.3.4-beta3: 1.0.0 => 2.3.4-beta3
1212
.EXAMPLE
1313
Bump the major, minor, patch or suffix part of the version.
14-
-b major: 1.2.3-alpha1 => 2.0.0
15-
-b minor: 1.2.3-alpha1 => 1.3.0
16-
-b patch: 1.2.3-alpha1 => 1.2.4
17-
-b suffix: 1.2.3-alpha => 1.2.3-alpha2
18-
-b suffix: 1.2.3-alpha2 => 1.2.3-alpha3
19-
-b suffix: 1.2.3-beta2 => 1.2.3-beta3
20-
-b suffix: 1.2.3-rc2 => 1.2.3-rc3
14+
-bump major: 1.2.3-alpha1 => 2.0.0
15+
-bump minor: 1.2.3-alpha1 => 1.3.0
16+
-bump patch: 1.2.3-alpha1 => 1.2.4
17+
-bump suffix: 1.2.3-alpha => 1.2.3-alpha2
18+
-bump suffix: 1.2.3-alpha2 => 1.2.3-alpha3
19+
-bump suffix: 1.2.3-beta2 => 1.2.3-beta3
20+
-bump suffix: 1.2.3-rc2 => 1.2.3-rc3
2121
2222
.NOTES
2323
Author: Andreas Gullberg Larsen
@@ -37,19 +37,29 @@
3737
)
3838

3939
function Help {
40-
"Sets the AssemblyVersion and AssemblyFileVersion of AssemblyInfo.cs files`n"
41-
".\SetVersion.ps1 [VersionNumber]`n"
42-
" [VersionNumber] The version number to set, for example: 1.1.9301.0"
43-
" If not provided, a version number will be generated.`n"
40+
"Sets the version of .csproj (or .props) files as well as versions in AssemblyInfo.cs files.`n"
41+
".\set-version.ps1 -Version 1.2.3-alpha`n"
42+
".\set-version.ps1 -Bump Major`n"
43+
".\set-version.ps1 -Bump Minor`n"
44+
".\set-version.ps1 -Bump Patch`n"
45+
".\set-version.ps1 -Bump Suffix`n"
4446
}
4547

46-
# Import functions: Set-ProjectVersion, Bump-ProjectVersion
47-
import-module "$PSScriptRoot\set-version.psm1"
48+
# Import functions: Get-NewProjectVersion, Set-ProjectVersion, Set-AssemblyInfoVersion, Invoke-CommitAndTagVersion
49+
Import-Module "$PSScriptRoot\set-version.psm1"
4850

51+
$root = Resolve-Path "$PSScriptRoot\.."
52+
$paramSet = $PsCmdlet.ParameterSetName
53+
$commonPropsFile = "$root\UnitsNet\UnitsNet.Common.props"
54+
$winrtAssemblyInfoFile = "$root\UnitsNet\Properties\AssemblyInfo.WindowsRuntimeComponent.cs"
55+
$winrtNuspecFile = "$root\UnitsNet\UnitsNet.WindowsRuntimeComponent.nuspec"
56+
$versionFiles = @($commonPropsFile, $winrtAssemblyInfoFile, $winrtNuspecFile)
57+
$projectName = "UnitsNet"
4958

50-
$root = "$PSScriptRoot\.."
51-
$paramSet = $PsCmdlet.ParameterSetName
52-
$projectPaths = @("$root\UnitsNet\UnitsNet.Common.props")
53-
$projectName = "UnitsNet"
59+
# Use UnitsNet.Common.props version as base if bumping major/minor/patch
60+
$newVersion = Get-NewProjectVersion $commonPropsFile $paramSet $setVersion $bumpVersion
5461

55-
Set-ProjectVersionAndCommit $projectName $projectPaths $paramSet $setVersion $bumpVersion
62+
Set-ProjectVersion $commonPropsFile $newVersion
63+
Set-AssemblyInfoVersion $winrtAssemblyInfoFile $newVersion
64+
Set-NuspecVersion $winrtNuspecFile $newVersion
65+
Invoke-CommitAndTagVersion $projectName $versionFiles $newVersion

Build/set-version.psm1

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,63 @@
1-
function Set-ProjectVersionAndCommit(
2-
[string]$projectName,
3-
[string[]]$projectPaths,
1+
function Get-NewProjectVersion(
2+
[string]$projectPath,
43
[string]$paramSet,
5-
[string]$setVersion,
6-
[string]$bumpVersion) {
4+
[string]$setVersionParam,
5+
[string]$bumpVersionParam) {
6+
switch ($paramSet) {
7+
"set" {
8+
return $setVersionParam
9+
}
10+
"bump" {
11+
return Get-BumpedProjectVersion $projectPath $bumpVersionParam
12+
}
13+
default {
14+
throw "Parameter set not implemented: $paramSet"
15+
}
16+
}
17+
}
718

19+
function Invoke-CommitAndTagVersion(
20+
[string]$projectName,
21+
[string[]]$projectPaths,
22+
[string] $newSemVer) {
823
try {
9-
foreach ($path in $projectPaths) {
10-
switch ($paramSet) {
11-
"set" {
12-
# Imported from module: set-version.psm1
13-
Set-ProjectVersion $path $setVersion
14-
$newSemVer = $setVersion
15-
}
16-
"bump" {
17-
# Imported from module: set-version.psm1
18-
$newSemVer = Set-BumpedProjectVersion $path $bumpVersion
19-
}
20-
default {
21-
throw "Parameter set not implemented: $paramSet"
22-
}
23-
}
24+
Write-Host -Foreground Green Resetting git index.
25+
git reset
26+
27+
ForEach ($path in $projectPaths) {
28+
$path = Resolve-Path $path
29+
Write-Host -Foreground Green "Staging file: $path"
30+
git add $path
2431
}
2532

26-
$gitAddProjects = [string]::Join(" ", $projectPaths)
27-
git add $gitAddProjects
33+
Write-Host -Foreground Green "Committing new versions: $projectName/$newSemVer"
2834
git commit -m "${projectName}: $newSemVer"
35+
Write-Host -Foreground Green "Tagging version: $projectName/$newSemVer"
2936
git tag -a "$projectName/$newSemVer" -m "$projectName/$newSemVer" -m "TODO List changes here"
30-
31-
Write-Host "New tag: $newSemVer"
3237
}
3338
catch {
34-
$ex = $Error[0]
35-
$err = Resolve-Error
36-
Write-Error "ERROR: Failed to update build parameters from .csproj file: `n---`n$err"
39+
$err = $PSItem.Exception
40+
Write-Error "ERROR: Failed to commit and tag version: `n---`n$err`n---`n$($PSItem.ScriptStackTrace)"
3741
exit 1
3842
}
3943
}
4044

41-
function Set-ProjectVersion([string] $projectPath, [string] $setVersion) {
42-
[xml]$projectXml = Get-Content -Path $projectPath
45+
function Set-ProjectVersion([string] $file, [string] $version) {
46+
Write-Host "$file -> $version"
47+
(Get-Content $file) -replace '<Version>.*?</Version>', "<Version>$version</Version>" | Set-Content $file
48+
}
4349

44-
Write-Host "$projectPath -> $setVersion"
50+
function Set-AssemblyInfoVersion([string] $file, [string] $version) {
51+
Write-Host "$file -> $version"
52+
(Get-Content $file) -replace 'Assembly(File)?Version\(".*?"\)', "Assembly`$1Version(`"$version`")" | Set-Content $file
53+
}
4554

46-
# Update <Version> property
47-
$projectXml.Project.PropertyGroup.Version = $setVersion
48-
$projectXml.Save($projectPath)
55+
function Set-NuspecVersion([string] $file, [string] $version) {
56+
Write-Host "$file -> $version"
57+
(Get-Content $file) -replace '<version>.*?</version>', "<version>$version</version>" | Set-Content $file
4958
}
5059

51-
function Set-BumpedProjectVersion([string] $projectPath, [string] $bumpVersion) {
60+
function Get-BumpedProjectVersion([string] $projectPath, [string] $bumpVersion) {
5261
[xml]$projectXml = Get-Content -Path $projectPath
5362

5463
$old = Get-ProjectVersionAndSuffix $projectXml
@@ -76,7 +85,6 @@ function Set-BumpedProjectVersion([string] $projectPath, [string] $bumpVersion)
7685
}
7786

7887
$newSemVer = $newVersion.ToString() + $newSuffix
79-
Set-ProjectVersion $projectPath $newSemVer
8088
return $newSemVer
8189
}
8290

@@ -112,7 +120,8 @@ function Get-ProjectVersionAndSuffix([xml] $projectXml) {
112120

113121
# Split "1.2.3-alpha" into ["1.2.3", "alpha"]
114122
# Split "1.2.3" into ["1.2.3"]
115-
$oldSemVer = $projectXml.Project.PropertyGroup.Version
123+
$oldSemVer = $($projectXml.Project.PropertyGroup.Version)[0]
124+
116125
$oldSemVerParts = $oldSemVer.Split('-')
117126
$oldVersion = $null
118127
if (-not [Version]::TryParse($oldSemVerParts[0], [ref] $oldVersion)) { throw "Unable to parse old version." }
@@ -141,4 +150,4 @@ function Resolve-Error ($ErrorRecord=$Error[0])
141150
}
142151
}
143152

144-
export-modulemember -function Set-ProjectVersionAndCommit, Set-ProjectVersion, Set-BumpedProjectVersion
153+
export-modulemember -function Get-NewProjectVersion, Set-ProjectVersion, Set-AssemblyInfoVersion, Invoke-CommitAndTagVersion, Set-NuspecVersion

CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Contributing to Units.NET
2+
3+
Guidelines for contributing to the repo.
4+
5+
## We want your help and we are friendly to first-time contributors!
6+
Adding a new unit or a new quantity is easy! We have detailed the steps here and if you need any assistance we are happy to help!
7+
8+
https://github.com/angularsen/UnitsNet/wiki/Adding-a-New-Unit
9+
10+
We also want the person with the idea, suggestion or bugreport to implement the change in code and get a sense of ownership for that piece of the library.
11+
This is to help grow the number of people that can contribute to the project and after someone new lands that first PR we often see more PRs from that person later.
12+
13+
## Coding Conventions
14+
* Match the existing code style, we generally stick to "Visual Studio defaults" and [.NET Foundation Coding Guidelines](https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md)
15+
* If you use ReSharper there is a [settings file](https://github.com/angularsen/UnitsNet/blob/master/UnitsNet.sln.DotSettings) that will take effect automatically
16+
* There is an [.editorconfig](https://github.com/angularsen/UnitsNet/blob/master/.editorconfig) to help configure whitespace and C# syntax for your editor if it supports it
17+
* Add the file header to new files you create
18+
19+
### Test Code
20+
* Test class: Use `Tests` suffix for the type you are testing, such as `UnitSystemTests`
21+
* Test method: `<method>_<condition>_<result>` (`Parse_AmbiguousUnits_ThrowsException`)
22+
* If there are many tests for a single method, you can wrap those in an inner class named the same as the method and then you can skip that part of the test method names
23+
24+
## Unit definitions (.JSON)
25+
For a fairly complete summary of the unit definition JSON schema, see [Meter of Length](https://github.com/angularsen/UnitsNet/blob/master/UnitsNet/UnitDefinitions/Length.json#L7). It has prefix units and multiple cultures.
26+
27+
### Conversion functions
28+
Converting from unit A to B is achieved by first converting from unit A to the base unit, then from the base unit to unit B. To achieve this, each unit defines two conversion functions.
29+
30+
* Prefer multiplication for `FromUnitToBaseFunc` (`x*2.54e-2` for `Inch` to `Meter`)
31+
* Prefer division for `FromBaseToUnitFunc` (`x/2.54e-2` for `Meter` to `Inch`)
32+
* Prefer scientific notation `1e3` and `1e-5` instead of `1000` and `0.00001`
33+
* Prefer a constant if the conversion factor is finite (`x*2.54e-2` for `Inch`)
34+
* Prefer a calculation if the conversion factor is infinite (`(x/72.27)*2.54e-2` for `PrinterPoint`)
35+
36+
### Units
37+
Generally we try to name the units as what is the most widely used.
38+
39+
* Use prefix for country variants, such as `ImperialGallon` and `UsGallon`
40+
41+
**Note:** We should really consider switching variant prefix to suffix, since that plays better with kilo, mega etc.. Currently we have units named `KilousGallon` and `KiloimperialGallon`, these would be better named `KilogallonUs` and `KilogallonImperial`.
42+
43+
### Unit abbreviations
44+
A unit can have multiple abbreviations per culture/language, the first one is used by `ToString()` while all of them are used by `Parse()`.
45+
46+
* Prefer the most widely used abbreviation in the domain, but try to adapt to our conventions
47+
* Add other popular variants to be able to parse those too, but take care to avoid abbreviation conflicts of units of the same quantity
48+
* Use superscript (`cm²`, ``) instead of `cm^2`, `m^3`
49+
* Use `` for delta (not ``)
50+
* Use `·` for products (`N·m` instead of `Nm`, `N*m` or `N.m`)
51+
* Prefer `/` over `⁻¹`, such as `km/h` and `J/(mol·K)`
52+
* Use `h` for hours, `min` for minutes and `s` for seconds (`m` is ambiguous with meters)
53+
* Use suffixes to distinguish variants of similar units, such as `gal (U.S.)` vs `gal (imp.)` for gallons
54+
* `(U.S.)` for United States
55+
* `(imp.)` for imperial / British units

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build status](https://ci.appveyor.com/api/projects/status/f8qfnqd7enkc6o4k?svg=true)](https://ci.appveyor.com/project/angularsen/unitsnet) [![Join the chat at https://gitter.im/UnitsNet/Lobby](https://badges.gitter.im/UnitsNet/Lobby.svg)](https://gitter.im/UnitsNet/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
1+
[![Build status](https://ci.appveyor.com/api/projects/status/f8qfnqd7enkc6o4k/branch/master?svg=true)](https://ci.appveyor.com/project/angularsen/unitsnet/history/branch/master) [![Join the chat at https://gitter.im/UnitsNet/Lobby](https://badges.gitter.im/UnitsNet/Lobby.svg)](https://gitter.im/UnitsNet/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
22
[![Flattr this git repo](https://button.flattr.com/flattr-badge-large.png)](https://flattr.com/submit/auto?fid=g37dpx&url=https://github.com/angularsen/UnitsNet/&title=Units.NET&language=en-US&tags=github&category=software)
33

44

@@ -246,3 +246,4 @@ http://www.nuget.org/packages/Microsoft.IoT.Devices (NuGet package)
246246
https://bitbucket.org/MartinEden/Crawlspace
247247

248248
*- Martin Eden, project maintainer*
249+

0 commit comments

Comments
 (0)