Skip to content

Commit

Permalink
v5 Release (#982)
Browse files Browse the repository at this point in the history
Fixes #180 

Merging the v5 release branch.

It is still in alpha, but it is functional, nugets are published and there are not many planned breaking changes left.
By merging, all efforts moving forward are targeting v5 and this reduces friction:

- No more merge conflicts trying to forward port all changes to v5, instead cherry pick new units and fixes to v4 until v5 is fully stable.
- Contributors are having trouble building v4 locally due to `net40`, `net47` and Windows Runtime Component targets.


## 💥 Breaking changes
Default number format should be CultureInfo.CurrentCulture, not CurrentUICulture (#795)
Use CurrentCulture rather than CurrentUICulture (#986)
Return `QuantityValue` in `IQuantity` properties instead of `double` (#1074)
Return `decimal` in properties of `Power`, `BitRate` and `Information` quantities (#1074)
Fix singular name VolumeFlow.MillionUsGallonsPerDay

## 🔥 Removed 
Remove targets: net40, net47, Windows Runtime Component.
Remove `Undefined` enum value for all unit enum types
Remove QuantityType enum
Remove IQuantity.Units and .UnitNames
Remove IQuantity.ToString() overloads
Remove IEquatable<T> and equality operators/methods 
Remove GlobalConfiguration
Remove obsolete and deprecated code.
Remove Molarity ctor and operator overloads
Remove MinValue, MaxValue per quantity due to ambiguity
Remove string format specifiers: "v", "s"
json: Remove UnitsNetJsonConverter

## ✨ New
QuantityValue: Implement IEquality, IComparable, IFormattable
QuantityValue: 16 bytes instead of 40 bytes (#1084)
Add `[DataContract]` annotations (#972)

## ♻️ Improvements
Upgrade CodeGen, tests and sample apps to net6.0.

## 📝 JSON unit definition schema changes
Rename `BaseType` to `ValueType`, for values "double" and "decimal".
Rename `XmlDoc` to `XmlDocSummary`.

## TODO
Add back `IEquatable<T>`, but implement as strict equality with tuple of quantity name + unit + value.
#1017 (comment)

## Postponed for later
#1067
  • Loading branch information
angularsen authored Nov 29, 2022
1 parent 7519a21 commit 9574d47
Show file tree
Hide file tree
Showing 1,290 changed files with 15,803 additions and 238,136 deletions.
33 changes: 3 additions & 30 deletions Build/build-functions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Update-GeneratedCode {
write-host -foreground blue "Generate code...END`n"
}

function Start-Build([boolean] $IncludeWindowsRuntimeComponent = $false, [boolean] $IncludeNanoFramework = $false) {
function Start-Build([boolean] $IncludeNanoFramework = $false) {
write-host -foreground blue "Start-Build...`n---"

$fileLoggerArg = "/logger:FileLogger,Microsoft.Build;logfile=$testReportDir\UnitsNet.msbuild.log"
Expand All @@ -40,24 +40,6 @@ function Start-Build([boolean] $IncludeWindowsRuntimeComponent = $false, [boolea
dotnet build --configuration Release "$root\UnitsNet.sln" $fileLoggerArg $appVeyorLoggerArg
if ($lastexitcode -ne 0) { exit 1 }

if (-not $IncludeWindowsRuntimeComponent)
{
write-host -foreground yellow "Skipping WindowsRuntimeComponent build."
}
else
{
write-host -foreground green "Build WindowsRuntimeComponent."
$fileLoggerArg = "/logger:FileLogger,Microsoft.Build;logfile=$testReportDir\UnitsNet.WindowsRuntimeComponent.msbuild.log"
$appVeyorLoggerArg = if (Test-Path "$appVeyorLoggerDll") { "/logger:$appVeyorLoggerDll" } else { "" }

# dontnet CLI does not support WindowsRuntimeComponent project type yet
# msbuild does not auto-restore nugets for this project type
write-host -foreground yellow "WindowsRuntimeComponent project not yet supported by dotnet CLI, using MSBuild15 instead"
& "$msbuild" "$root\UnitsNet.WindowsRuntimeComponent.sln" /verbosity:minimal /p:Configuration=Release /t:restore
& "$msbuild" "$root\UnitsNet.WindowsRuntimeComponent.sln" /verbosity:minimal /p:Configuration=Release $fileLoggerArg $appVeyorLoggerArg
if ($lastexitcode -ne 0) { exit 1 }
}

if (-not $IncludeNanoFramework)
{
write-host -foreground yellow "Skipping .NET nanoFramework build."
Expand All @@ -82,8 +64,7 @@ function Start-Tests {
$projectPaths = @(
"UnitsNet.Tests\UnitsNet.Tests.csproj",
"UnitsNet.NumberExtensions.Tests\UnitsNet.NumberExtensions.Tests.csproj",
"UnitsNet.Serialization.JsonNet.Tests\UnitsNet.Serialization.JsonNet.Tests.csproj",
"UnitsNet.Serialization.JsonNet.CompatibilityTests\UnitsNet.Serialization.JsonNet.CompatibilityTests.csproj"
"UnitsNet.Serialization.JsonNet.Tests\UnitsNet.Serialization.JsonNet.Tests.csproj"
)

# Parent dir must exist before xunit tries to write files to it
Expand Down Expand Up @@ -129,21 +110,13 @@ function Start-PackNugets {
if ($lastexitcode -ne 0) { exit 1 }
}

if (-not $IncludeWindowsRuntimeComponent) {
write-host -foreground yellow "Skipping WindowsRuntimeComponent nuget pack."
} else {
write-host -foreground yellow "WindowsRuntimeComponent project not yet supported by dotnet CLI, using nuget.exe instead"
& $nuget pack "$root\UnitsNet.WindowsRuntimeComponent\UnitsNet.WindowsRuntimeComponent.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir"
}

if (-not $IncludeNanoFramework) {
write-host -foreground yellow "Skipping nanoFramework nuget pack."
} else {
write-host -foreground yellow "nanoFramework project not yet supported by dotnet CLI, using nuget.exe instead"
Invoke-Build-NanoNugets
Invoke-BuildNanoNugets
}


write-host -foreground blue "Pack nugets...END`n"
}

Expand Down
4 changes: 2 additions & 2 deletions Build/build-pack-nano-nugets.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$nugetOutDir = "$root\Artifacts\NuGet"
$nuget = "$root\Tools\NuGet.exe"

function Invoke-Build-NanoNugets {
function Invoke-BuildNanoNugets {

& $nuget pack "$root\UnitsNet.NanoFramework\GeneratedCode\Duration\UnitsNet.NanoFramework.Duration.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir"
& $nuget pack "$root\UnitsNet.NanoFramework\GeneratedCode\ElectricCurrent\UnitsNet.NanoFramework.ElectricCurrent.nuspec" -Verbosity detailed -OutputDirectory "$nugetOutDir"
Expand All @@ -25,4 +25,4 @@ function Invoke-Build-NanoNugets {

}

export-modulemember -function Invoke-Build-NanoNugets
export-modulemember -function Invoke-BuildNanoNugets
8 changes: 2 additions & 6 deletions Build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@
Publishing nugets is handled by nuget-publish.bat and run by the build server
on the master branch.
.PARAMETER skipUWP
If flag is set, will skip the UWP (Windows Runtime Component) build step as this requires
some large, extra Visual Studio features to be installed.
.EXAMPLE
powershell ./build.ps1
powershell ./build.ps1 -IncludeWindowsRuntimeComponent -IncludeNanoFramework
powershell ./build.ps1 -IncludeNanoFramework
.NOTES
Author: Andreas Gullberg Larsen
Last modified: Jan 21, 2018
#>
[CmdletBinding()]
Param(
[switch] $IncludeWindowsRuntimeComponent,
[switch] $IncludeNanoFramework
)

Expand All @@ -32,7 +28,7 @@ try {

Remove-ArtifactsDir
Update-GeneratedCode
Start-Build -IncludeWindowsRuntimeComponent $IncludeWindowsRuntimeComponent -IncludeNanoFramework $IncludeNanoFramework
Start-Build -IncludeNanoFramework $IncludeNanoFramework
Start-Tests
Start-PackNugets
Compress-ArtifactsAsZip
Expand Down
15 changes: 10 additions & 5 deletions Build/init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,24 @@ if (!(Test-Path "$msbuildPath/nanoFramework")) {
$extensionVersion = $vs2019Tag
}

Write-Output "Downloading visx..." -NoNewline
Write-Output "Downloading visx..."

# download VS extension
Write-Debug "Download VSIX file from $extensionUrl to $vsixPath"
Write-Host "Download VSIX file from $extensionUrl to $vsixPath"
$webClient.DownloadFile($extensionUrl, $vsixPath)

$outputPath = "$tempDir\nf-extension"

$vsixPath = Join-Path -Path $tempDir -ChildPath "nf-extension.zip"
$webClient.DownloadFile($extensionUrl,$vsixPath)
Expand-Archive -LiteralPath $vsixPath -DestinationPath $outputPath | Write-Host
$webClient.DownloadFile($extensionUrl, $vsixPath)

Write-Host "Extract VSIX file to $outputPath"
Expand-Archive -LiteralPath $vsixPath -DestinationPath $outputPath -Force | Write-Host

$copyFrom = "$outputPath\`$MSBuild\nanoFramework"

Copy-Item -Path "$outputPath\`$MSBuild\nanoFramework" -Destination $msbuildPath -Recurse
Write-Host "Copy from $copyFrom to $msbuildPath"
Copy-Item -Path "$copyFrom" -Destination $msbuildPath -Recurse

Write-Host "Installed VS extension $extensionVersion"
}
Expand Down
8 changes: 0 additions & 8 deletions Build/set-version-UnitsNet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ $projFile = "$root\UnitsNet\UnitsNet.csproj"
$numberExtensionsProjFile = "$root\UnitsNet.NumberExtensions\UnitsNet.NumberExtensions.csproj"
$nanoFrameworkNuspecGeneratorFile = "$root\CodeGen\Generators\NanoFrameworkGen\NuspecGenerator.cs"
$nanoFrameworkAssemblyInfoFile = "$root\UnitsNet.NanoFramework\GeneratedCode\Properties\AssemblyInfo.cs"
$winrtAssemblyInfoFile = "$root\UnitsNet.WindowsRuntimeComponent\Properties\AssemblyInfo.cs"
$winrtNuspecFile = "$root\UnitsNet.WindowsRuntimeComponent\UnitsNet.WindowsRuntimeComponent.nuspec"

# Use UnitsNet.Common.props version as base if bumping major/minor/patch
$newVersion = Get-NewProjectVersion $projFile $paramSet $setVersion $bumpVersion
Expand All @@ -68,15 +66,9 @@ $didStash = Invoke-StashPush
Set-ProjectVersion $projFile $newVersion
Set-ProjectVersion $numberExtensionsProjFile $newVersion

# Update AssemblyInfo.cs files
Set-AssemblyInfoVersion $winrtAssemblyInfoFile $newVersion

# Update AssemblyInfo.cs file for .NET nanoFramework
Set-AssemblyInfoVersion $nanoFrameworkAssemblyInfoFile $newVersion

# Update .nuspec files
Set-NuspecVersion $winrtNuspecFile $newVersion

# Update codegen and .nuspec files for nanoFramework
Set-NuspecVersion $nanoFrameworkNuspecGeneratorFile $newVersion
Get-ChildItem -Path "$root\UnitsNet.NanoFramework\GeneratedCode" -Include '*.nuspec' -Recurse |
Expand Down
16 changes: 16 additions & 0 deletions Build/set-version-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# Sets version of nuget UnitNets.Serialization.JsonNet.
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
set_version_script="$script_dir/set-version-UnitsNet.Serialization.JsonNet.ps1"

if [ $# -eq 1 ]; then
powershell -NoProfile $set_version_script -setVersion $1
exit 0
else
echo "Usage: ./set-version-json.sh <version>"
echo ""
echo "Examples:"
echo "$ ./set-version-json.sh 5.0.0-alpha001"
echo "$ ./set-version-json.sh 5.1.2"
exit 1
fi
2 changes: 1 addition & 1 deletion CodeGen/CodeGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp5.0</TargetFramework>
<TargetFramework>netcoreapp6.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<!-- Allow compile with various nullability warnings until fixed. -->
Expand Down
5 changes: 2 additions & 3 deletions CodeGen/Generators/GeneratorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ namespace CodeGen.Generators
{
internal abstract class GeneratorBase
{
protected readonly MyTextWriter Writer = new MyTextWriter();
public abstract string Generate();
protected readonly MyTextWriter Writer = new();

public const string GeneratedFileHeader = @"//------------------------------------------------------------------------------
protected const string GeneratedFileHeader = @"//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by \generate-code.bat.
//
Expand Down
6 changes: 3 additions & 3 deletions CodeGen/Generators/NanoFrameworkGen/NuspecGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public NuspecGenerator(
_mathNuGetVersion = mathNuGetVersion;
}

public override string Generate()
public string Generate()
{
Writer.WL($@"<?xml version=""1.0"" encoding=""utf-8""?>
<package xmlns=""http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"">
<metadata>
<id>UnitsNet.nanoFramework.{_quantity.Name}</id>
<version>4.149.0</version>
<version>5.0.0-alpha006</version>
<title>Units.NET {_quantity.Name} - nanoFramework</title>
<authors>Andreas Gullberg Larsen,nanoFramework project contributors</authors>
<owners>UnitsNet</owners>
Expand All @@ -38,7 +38,7 @@ public override string Generate()
</releaseNotes>
<copyright>Copyright 2013 Andreas Gullberg Larsen ([email protected]).</copyright>
<language>en-US</language>
<tags>nanoframework unit units measurement si metric imperial abbreviation abbreviations convert conversion parse c# .net immutable uwp uap winrt win10 windows runtime component {_quantity.Name.ToLower()}</tags>
<tags>nanoframework {_quantity.Name.ToLower()} unit units quantity quantities measurement si metric imperial abbreviation abbreviations convert conversion parse immutable</tags>
<dependencies>
<dependency id=""nanoFramework.CoreLibrary"" version=""{_mscorlibNuGetVersion}"" />");

Expand Down
2 changes: 1 addition & 1 deletion CodeGen/Generators/NanoFrameworkGen/ProjectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public ProjectGenerator(Quantity quantity, NanoFrameworkVersions versions)
_versions = versions;
}

public override string Generate()
public string Generate()
{
Writer.WL($@"<?xml version=""1.0"" encoding=""utf-8""?>
<Project ToolsVersion=""15.0"" DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
Expand Down
2 changes: 1 addition & 1 deletion CodeGen/Generators/NanoFrameworkGen/PropertyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public PropertyGenerator(string version)
_version = version;
}

public override string Generate()
public string Generate()
{
Writer.WL(GeneratedFileHeader);
Writer.W($@"using System.Reflection;
Expand Down
Loading

0 comments on commit 9574d47

Please sign in to comment.