Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 1 addition & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,10 @@ jobs:
6.0.x
8.0.x

- name: Setup .NET nanoFramework build components
uses: nanoframework/nanobuild@v1
with:
workload: 'nanoFramework'

- name: Build, Test and Pack
shell: pwsh
run: |
./Build/build.ps1 -IncludeNanoFramework
./Build/build.ps1
working-directory: ${{ github.workspace }}

- name: Upload to codecov.io
Expand Down
7 changes: 1 addition & 6 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,10 @@ jobs:
6.0.x
8.0.x

- name: Setup .NET nanoFramework build components
uses: nanoframework/nanobuild@v1
with:
workload: 'nanoFramework'

- name: Build, Test and Pack
shell: pwsh
run: |
./Build/build.ps1 -IncludeNanoFramework
./Build/build.ps1
working-directory: ${{ github.workspace }}

- name: Upload Test Results
Expand Down
7 changes: 0 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ UnitsNet is a .NET library that provides strongly-typed physical units and quant

### Build and Test
- **Build project**: `build.bat` or `dotnet build UnitsNet.slnx`
- **Build all targets** (including nanoFramework): `build-all-targets.bat`
- **Run tests**: `test.bat` or `dotnet test UnitsNet.slnx`
- **Run single test**: `dotnet test UnitsNet.Tests --filter "FullyQualifiedName~TestClassName.TestMethodName"`
- **Clean artifacts**: `clean.bat`
Expand All @@ -37,7 +36,6 @@ UnitsNet is a .NET library that provides strongly-typed physical units and quant
- **Common/UnitDefinitions/**: 131 JSON files defining physical quantities
- **UnitsNet.NumberExtensions/**: Extension methods for numeric types
- **UnitsNet.Serialization.*/**: JSON.NET and System.Text.Json serialization support
- **UnitsNet.NanoFramework/**: Support for embedded .NET nanoFramework

### Code Generation Process
The project uses a sophisticated code generation system:
Expand Down Expand Up @@ -87,11 +85,6 @@ The project uses a sophisticated code generation system:

## Special Considerations

### .NET nanoFramework Support
- Separate projects for nanoFramework compatibility
- Use `build-all-targets.bat` to include nanoFramework builds
- Limited feature set compared to full .NET

### Performance
- Conversion functions are compiled to delegates for performance
- All conversions go through base units (potential for small errors)
Expand Down
73 changes: 1 addition & 72 deletions Build/build-functions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@ $testReportDir = "$artifactsDir\TestResults"
$testCoverageDir = "$artifactsDir\Coverage"
$toolsDir = "$root\.tools"

$nuget = "$toolsDir\NuGet.exe"
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"

# Check if Visual Studio is installed before trying to find MSBuild
if (Test-Path $vswhere) {
$msbuildPath = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath 2>$null

if ($msbuildPath) {
$msbuildx64 = join-path $msbuildPath 'MSBuild\Current\Bin\amd64\MSBuild.exe'
}
} else {
$msbuildPath = $null
$msbuildx64 = $null
}

import-module $PSScriptRoot\build-pack-nano-nugets.psm1

function Remove-ArtifactsDir {
if (Test-Path $artifactsDir) {
write-host -foreground blue "Clean up...`n"
Expand All @@ -48,44 +31,6 @@ function Start-Build {
write-host -foreground blue "Start-Build...END`n"
}

function Start-BuildNanoFramework {
write-host -foreground blue "Start-BuildNanoFramework (MSBuild)...`n---"

# Check prerequisites
if (-not $msbuildx64 -or -not (Test-Path $msbuildx64)) {
write-host -foreground red "ERROR: Cannot build .NET nanoFramework - MSBuild not found."
write-host -foreground yellow "Install Visual Studio with .NET desktop development workload to build NanoFramework projects."
exit 1
}

if (-not (Test-Path $nuget)) {
write-host -foreground red "ERROR: NuGet.exe not found at $nuget"
write-host -foreground yellow "Run init.ps1 to download required tools."
exit 1
}

write-host -foreground green "Building .NET nanoFramework projects..."
$fileLoggerArg = "/logger:FileLogger,Microsoft.Build;logfile=$logsDir\UnitsNet.NanoFramework.msbuild.log"

# msbuild does not auto-restore nugets for this project type
write-host "Restoring NuGet packages for NanoFramework..."
& "$nuget" restore "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln"
if ($lastexitcode -ne 0) {
write-host -foreground red "Failed to restore NuGet packages for NanoFramework"
exit 1
}

# Build with MSBuild
write-host "Building NanoFramework solution..."
& "$msbuildx64" "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln" /verbosity:minimal /p:Configuration=Release /p:Platform="Any CPU" /p:ContinuousIntegrationBuild=true $fileLoggerArg
if ($lastexitcode -ne 0) {
write-host -foreground red "Failed to build NanoFramework solution"
exit 1
}

write-host -foreground blue "Start-BuildNanoFramework...END`n"
}

function Start-Tests {
$projectPaths = @(
"UnitsNet.Tests\UnitsNet.Tests.csproj",
Expand Down Expand Up @@ -148,22 +93,6 @@ function Start-PackNugets {
write-host -foreground blue "Pack nugets...END`n"
}

function Start-PackNugetsNanoFramework {
write-host -foreground blue "Pack NanoFramework nugets (NuGet.exe)...`n---"

# Check prerequisites
if (-not (Test-Path $nuget)) {
write-host -foreground red "ERROR: NuGet.exe not found at $nuget"
write-host -foreground yellow "Run init.ps1 to download required tools."
exit 1
}

write-host -foreground yellow "nanoFramework project not yet supported by dotnet CLI, using nuget.exe instead"
Invoke-BuildNanoNugets

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

function Compress-ArtifactsAsZip {
write-host -foreground blue "Zip artifacts...`n---"

Expand All @@ -184,4 +113,4 @@ function Compress-ArtifactsAsZip {
write-host -foreground blue "Zip artifacts...END`n"
}

export-modulemember -function Remove-ArtifactsDir, Update-GeneratedCode, Start-Build, Start-BuildNanoFramework, Start-Tests, Start-PackNugets, Start-PackNugetsNanoFramework, Compress-ArtifactsAsZip
export-modulemember -function Remove-ArtifactsDir, Update-GeneratedCode, Start-Build, Start-Tests, Start-PackNugets, Compress-ArtifactsAsZip
14 changes: 0 additions & 14 deletions Build/build-pack-nano-nugets.psm1

This file was deleted.

15 changes: 1 addition & 14 deletions Build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
on the master branch.
.EXAMPLE
powershell ./build.ps1
powershell ./build.ps1 -IncludeNanoFramework

.NOTES
Author: Andreas Gullberg Larsen
Last modified: Jan 21, 2018
#>
[CmdletBinding()]
Param(
[switch] $IncludeNanoFramework
)
Param()

remove-module build-functions -ErrorAction SilentlyContinue
import-module $PSScriptRoot\build-functions.psm1
Expand All @@ -34,16 +31,6 @@ try {
Start-Tests
Start-PackNugets

# Build NanoFramework if requested (Windows-only, requires Visual Studio)
if ($IncludeNanoFramework) {
write-host -foreground cyan "`n===== Building NanoFramework projects (requires Visual Studio) =====`n"
Start-BuildNanoFramework
Start-PackNugetsNanoFramework
}
else {
write-host -foreground yellow "`nSkipping NanoFramework build. Use -IncludeNanoFramework flag to build NanoFramework projects.`n"
}

Compress-ArtifactsAsZip
}
catch {
Expand Down
103 changes: 0 additions & 103 deletions Build/init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,122 +2,19 @@
Set-Strictmode -version latest

$root = (Resolve-Path "$PSScriptRoot\..").Path
$nugetPath = "$root/.tools/NuGet.exe"

Write-Host -Foreground Blue "Initializing..."

# Ensure temp dir exists
$tempDir = "$root/.tools/temp_init"
[system.io.Directory]::CreateDirectory($tempDir) | out-null

# Report generator for unit test coverage reports.
if (-not (Test-Path "$root/.tools/reportgenerator.exe")) {
Write-Host -Foreground Blue "Install dotnet-reportgenerator-globaltool..."
dotnet tool install dotnet-reportgenerator-globaltool --tool-path .tools
Write-Host -Foreground Green "✅ Installed dotnet-reportgenerator-globaltool"
}

# NuGet.exe for non-SDK style projects, like UnitsNet.nanoFramework.
if (-not (Test-Path "$nugetPath")) {
Write-Host -Foreground Blue "Downloading NuGet.exe..."
Invoke-WebRequest -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile $nugetPath
Write-Host -Foreground Green "✅ Downloaded NuGet.exe: $nugetPath"
}

###################################################
## TODO: OK to remove after moving to AZDO pipeline
$VsWherePath = "${env:PROGRAMFILES(X86)}\Microsoft Visual Studio\Installer\vswhere.exe"

# Check if Visual Studio is installed
if (Test-Path $VsWherePath) {
$VsPath = $(&$VsWherePath -latest -property installationPath 2>$null)
if ($VsPath) {
$msbuildPath = Join-Path -Path $VsPath -ChildPath "\MSBuild"
Write-Host -Foreground Green "Visual Studio found at: $VsPath"
} else {
Write-Host -Foreground Yellow "Visual Studio not found via vswhere, NanoFramework builds will be skipped"
$VsPath = $null
$msbuildPath = $null
}
} else {
Write-Host -Foreground Yellow "Visual Studio not installed - NanoFramework builds will be skipped"
$VsPath = $null
$msbuildPath = $null
}

# Install dotnet CLI tools declared in /.config/dotnet-tools.json
pushd $root
dotnet tool restore
popd

# Install .NET nanoFramework build components
if ($msbuildPath -and !(Test-Path "$msbuildPath/nanoFramework")) {
Write-Host "Installing .NET nanoFramework VS extension..."

[System.Net.WebClient]$webClient = New-Object System.Net.WebClient
$webClient.Headers.Add("User-Agent", "request")
$webClient.Headers.Add("Accept", "application/vnd.github.v3+json")

$releaseList = $webClient.DownloadString('https://api.github.com/repos/nanoframework/nf-Visual-Studio-extension/releases?per_page=100')

if($releaseList -match '\"(?<VS2022_version>v2022\.\d+\.\d+\.\d+)\"')
{
$vs2022Tag = $Matches.VS2022_version
}

if($releaseList -match '\"(?<VS2019_version>v2019\.\d+\.\d+\.\d+)\"')
{
$vs2019Tag = $Matches.VS2019_version
}

# Find which VS version is installed
$VsWherePath = "${env:PROGRAMFILES(X86)}\Microsoft Visual Studio\Installer\vswhere.exe"

Write-Output "VsWherePath is: $VsWherePath"

$VsInstance = $(&$VSWherePath -latest -property displayName 2>$null)

Write-Output "Latest VS is: $VsInstance"

# Get extension details according to VS version, starting from VS2022 down to VS2019
# TODO check if the extension for VS2022 is compatible it VS2026
if($vsInstance.Contains('2026') -or $vsInstance.Contains('2022'))
{
$extensionUrl = "https://github.com/nanoframework/nf-Visual-Studio-extension/releases/download/$vs2022Tag/nanoFramework.Tools.VS2022.Extension.vsix"
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2022.Extension.zip"
$extensionVersion = $vs2022Tag
}
elseif($vsInstance.Contains('2019'))
{
$extensionUrl = "https://github.com/nanoframework/nf-Visual-Studio-extension/releases/download/$vs2019Tag/nanoFramework.Tools.VS2019.Extension.vsix"
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2019.Extension.zip"
$extensionVersion = $vs2019Tag
}

Write-Output "Downloading visx..."

# download VS extension
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)

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

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

Write-Host "Copy from $copyFrom to $msbuildPath"
Copy-Item -Path "$copyFrom" -Destination $msbuildPath -Recurse

Write-Host "Installed VS extension $extensionVersion"
}
###################################################

# Cleanup
[system.io.Directory]::Delete($tempDir, $true) | out-null

Write-Host -Foreground Green "Initialized."
13 changes: 0 additions & 13 deletions Build/set-version-UnitsNet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ $root = Resolve-Path "$PSScriptRoot\.."
$paramSet = $PsCmdlet.ParameterSetName
$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"

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

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

# Update codegen and .nuspec files for nanoFramework
Set-NuspecVersion $nanoFrameworkNuspecGeneratorFile $newVersion
Get-ChildItem -Path "$root\UnitsNet.NanoFramework\GeneratedCode" -Include '*.nuspec' -Recurse |
Foreach-object {
Set-NuspecVersion $_.FullName $newVersion
$versionFiles += $_.FullName
}

# Git commit and tag
Invoke-CommitVersionBump @("UnitsNet") $newVersion
Invoke-TagVersionBump "UnitsNet" $newVersion
Expand Down
Loading
Loading