Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Mar 27, 2024
1 parent 34a203d commit 063293f
Show file tree
Hide file tree
Showing 30 changed files with 675 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ------------------------------------------------------------------------------
# Build.yml
# ------------------------------------------------------------------------------

name: Build

on:
push:
pull_request:
branches-ignore:
- master
- main
workflow_dispatch:

jobs:
Build:
name: Build
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- name: Run './build/build.cmd'
run: ./build/build.cmd --root ./build
env:
GitHubToken: ${{ secrets.GITHUB_TOKEN }}
SignFile: ${{ secrets.SIGN_FILE }}
SignPassword: ${{ secrets.SIGN_PASSWORD }}
11 changes: 11 additions & 0 deletions Build/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[*.cs]
dotnet_style_qualification_for_field = false:warning
dotnet_style_qualification_for_property = false:warning
dotnet_style_qualification_for_method = false:warning
dotnet_style_qualification_for_event = false:warning
dotnet_style_require_accessibility_modifiers = never:warning

csharp_style_expression_bodied_methods = true:silent
csharp_style_expression_bodied_properties = true:warning
csharp_style_expression_bodied_indexers = true:warning
csharp_style_expression_bodied_accessors = true:warning
4 changes: 4 additions & 0 deletions Build/.nuke/parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "./build.schema.json",
"Solution": "../RevitVersion.DefineConstants.sln"
}
9 changes: 9 additions & 0 deletions Build/Build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Nuke.Common;
using Nuke.Common.Execution;
using ricaun.Nuke;
using ricaun.Nuke.Components;

class Build : NukeBuild, IPublishPack, IPrePack
{
public static int Main() => Execute<Build>(x => x.From<IPublishPack>().Build);
}
21 changes: 21 additions & 0 deletions Build/Build.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>.</NukeRootDirectory>
<NukeScriptDirectory>.</NukeScriptDirectory>
<NukeTelemetryVersion>1</NukeTelemetryVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ricaun.Nuke" Version="*" />
</ItemGroup>

<ItemGroup>
<None Include="..\.github\workflows\*.yml" LinkBase="ci" />
<None Include=".github\**\*"/>
<None Include=".nuke\*"/>
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions Build/build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:; set -eo pipefail
:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
:; ${SCRIPT_DIR}/build.sh "$@"
:; exit $?

@ECHO OFF
powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %*
69 changes: 69 additions & 0 deletions Build/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[CmdletBinding()]
Param(
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$BuildArguments
)

Write-Output "PowerShell $($PSVersionTable.PSEdition) version $($PSVersionTable.PSVersion)"

Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { Write-Error $_ -ErrorAction Continue; exit 1 }
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent

###########################################################################
# CONFIGURATION
###########################################################################

$BuildProjectFile = "$PSScriptRoot\Build.csproj"
$TempDirectory = "$PSScriptRoot\\.nuke\temp"

$DotNetGlobalFile = "$PSScriptRoot\\global.json"
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
$DotNetChannel = "Current"

$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
$env:DOTNET_MULTILEVEL_LOOKUP = 0

###########################################################################
# EXECUTION
###########################################################################

function ExecSafe([scriptblock] $cmd) {
& $cmd
if ($LASTEXITCODE) { exit $LASTEXITCODE }
}

# If dotnet CLI is installed globally and it matches requested version, use for execution
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and `
$(dotnet --version) -and $LASTEXITCODE -eq 0) {
$env:DOTNET_EXE = (Get-Command "dotnet").Path
}
else {
# Download install script
$DotNetInstallFile = "$TempDirectory\dotnet-install.ps1"
New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile)

# If global.json exists, load expected version
if (Test-Path $DotNetGlobalFile) {
$DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json)
if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) {
$DotNetVersion = $DotNetGlobal.sdk.version
}
}

# Install by channel or version
$DotNetDirectory = "$TempDirectory\dotnet-win"
if (!(Test-Path variable:DotNetVersion)) {
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
} else {
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
}
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
}

Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)"

ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet }
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }
62 changes: 62 additions & 0 deletions Build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

bash --version 2>&1 | head -n 1

set -eo pipefail
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)

###########################################################################
# CONFIGURATION
###########################################################################

BUILD_PROJECT_FILE="$SCRIPT_DIR/Build.csproj"
TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp"

DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
DOTNET_CHANNEL="Current"

export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_MULTILEVEL_LOOKUP=0

###########################################################################
# EXECUTION
###########################################################################

function FirstJsonValue {
perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}"
}

# If dotnet CLI is installed globally and it matches requested version, use for execution
if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then
export DOTNET_EXE="$(command -v dotnet)"
else
# Download install script
DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
mkdir -p "$TEMP_DIRECTORY"
curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
chmod +x "$DOTNET_INSTALL_FILE"

# If global.json exists, load expected version
if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then
DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")")
if [[ "$DOTNET_VERSION" == "" ]]; then
unset DOTNET_VERSION
fi
fi

# Install by channel or version
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
if [[ -z ${DOTNET_VERSION+x} ]]; then
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path
else
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
fi
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
fi

echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)"

"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.0.0] / YYYY-MM-DD
- First Release

[vNext]: ../../compare/1.0.0...HEAD
[1.0.0]: ../../compare/1.0.0
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 ricaun

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# RevitVersion.DefineConstants

[![Revit 2017](https://img.shields.io/badge/Revit-2017...2025-blue.svg)](../..)
[![Visual Studio 2022](https://img.shields.io/badge/Visual%20Studio-2022-blue)](../..)
[![Nuke](https://img.shields.io/badge/Nuke-Build-blue)](https://nuke.build/)
[![License MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Build](../../actions/workflows/Build.yml/badge.svg)](../../actions)

## License

This project is [licensed](LICENSE) under the [MIT Licence](https://en.wikipedia.org/wiki/MIT_License).

---

Do you like this project? Please [star this project on GitHub](../../stargazers)!
90 changes: 90 additions & 0 deletions RevitVersion.DefineConstants.Sample/Revit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
namespace RevitVersion.DefineConstants.Sample
{
public class Revit
{
#if REVIT2025
public class Revit2025 { }
#endif
#if REVIT2024
public class Revit2024 { }
#endif
#if REVIT2023
public class Revit2023 { }
#endif
#if REVIT2022
public class Revit2022 { }
#endif
#if REVIT2021
public class Revit2021 { }
#endif
#if REVIT2020
public class Revit2020 { }
#endif
#if REVIT2019
public class Revit2019 { }
#endif
#if REVIT2018
public class Revit2018 { }
#endif
#if REVIT2017
public class Revit2017 { }
#endif


#if REVIT2025_OR_LESS
public class Revit2025OrLess { }
#endif
#if REVIT2024_OR_LESS
public class Revit2024OrLess { }
#endif
#if REVIT2023_OR_LESS
public class Revit2023OrLess { }
#endif
#if REVIT2022_OR_LESS
public class Revit2022OrLess { }
#endif
#if REVIT2021_OR_LESS
public class Revit2021OrLess { }
#endif
#if REVIT2020_OR_LESS
public class Revit2020OrLess { }
#endif
#if REVIT2019_OR_LESS
public class Revit2019OrLess { }
#endif
#if REVIT2018_OR_LESS
public class Revit2018OrLess { }
#endif
#if REVIT2017_OR_LESS
public class Revit2017OrLess { }
#endif

#if REVIT2025_OR_GREATER
public class Revit2025OrGreater { }
#endif
#if REVIT2024_OR_GREATER
public class Revit2024OrGreater { }
#endif
#if REVIT2023_OR_GREATER
public class Revit2023OrGreater { }
#endif
#if REVIT2022_OR_GREATER
public class Revit2022OrGreater { }
#endif
#if REVIT2021_OR_GREATER
public class Revit2021OrGreater { }
#endif
#if REVIT2020_OR_GREATER
public class Revit2020OrGreater { }
#endif
#if REVIT2019_OR_GREATER
public class Revit2019OrGreater { }
#endif
#if REVIT2018_OR_GREATER
public class Revit2018OrGreater { }
#endif
#if REVIT2017_OR_GREATER
public class Revit2017OrGreater { }
#endif
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<RevitVersion>2023</RevitVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="RevitVersion.DefineConstants" Version="*-*" />
</ItemGroup>

</Project>
Loading

0 comments on commit 063293f

Please sign in to comment.