Skip to content

Commit 6746f01

Browse files
authored
Make it core-clr compatible and unix-friendly (#329)
* Make C# part CoreCLR-friendly * Update csproj files * xUnit tests pass on mac OS * Switch build.psd1 to dotnet cli * Remove old .nuget folder * Replace powershell aliases by full names for cross-plat compatability * Fix FullLoop.Tests.ps1 * Fix PlatyPs.Tests.ps1 * Fix appveyor and build.ps1 * Explicitly query IsLinux and IsMacOS in tests * Update build docs * add .travis.yml * Fix casing in tests and build.ps1 * don't overwrite IsLinux and IsOsMac * Silent Write-Progress on coreclr * Make platyPS target net451 on windows
1 parent f7ca303 commit 6746f01

33 files changed

+331
-754
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ ModelManifest.xml
193193
# Out project specific stuff
194194
generatedMarkdown.txt
195195
out/
196+
publish/
196197

197198
# For developing in VSCode
198199
.vscode/launch.json

.nuget/NuGet.Config

Lines changed: 0 additions & 6 deletions
This file was deleted.

.nuget/NuGet.exe

-1.61 MB
Binary file not shown.

.nuget/NuGet.targets

Lines changed: 0 additions & 144 deletions
This file was deleted.

.travis.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# that gives us dotnet cli installed on the box
2+
language: csharp
3+
4+
dist: trusty
5+
sudo: required
6+
7+
mono: none
8+
dotnet: 2.0.0
9+
10+
# instruction from https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md#ubuntu-1404
11+
12+
install:
13+
- curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
14+
- curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
15+
- sudo apt-get update
16+
- sudo apt-get install -y powershell
17+
18+
script:
19+
- pwsh ./build.ps1
20+
- dotnet test ./test/Markdown.MAML.Test
21+
- sudo pwsh -C 'Install-Module Pester -Force'
22+
# updated help is needed for tests, run as a Job to avoid Write-Progress output
23+
- sudo pwsh -C '(update-help &) | Wait-Job'
24+
- pwsh -C 'Invoke-Pester -EnableExit'

CONTRIBUTING.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,14 @@ There are two parts:
1010

1111
- `Markdown.MAML.dll`, a .NET library written in C#.
1212
It does the heavy lifting, like parsing Markdown, transforming it into XML, and so on.
13-
You can open `.\Markdown.MAML.sln` in Visual Studio 2015.
13+
You can open `.\Markdown.MAML.sln` in Visual Studio on any platform.
1414
- A PowerShell module in `.\src\platyPS`.
1515
This module provides the user CLI.
1616

17-
## First-time setup
18-
19-
Restore NuGet packages.
20-
You can do this from Visual Studio, or from the command line.
21-
22-
```
23-
.\.nuget\NuGet.exe restore
24-
```
25-
2617
## Build
2718

2819
To build the whole project, use the `build.ps1` helper script.
20+
It depends on the [dotnet cli](https://docs.microsoft.com/en-us/dotnet/core/tools/) build tool.
2921

3022
```
3123
.\build.ps1
@@ -44,12 +36,9 @@ If you know a better workflow, please suggest it in the Issues.
4436
Each part of the project has a test set:
4537

4638
- The C# part has xUnit tests.
47-
You can run them with xUnit from Visual Studio.
39+
You can run them from Visual Studio or from command line with `dotnet test ./test/Markdown.MAML.Test`.
4840
- The PowerShell part has [Pester](https://github.com/pester/Pester) tests.
49-
You can run them using:
50-
```
51-
Invoke-Pester
52-
```
41+
You can run them with `Invoke-Pester`.
5342

5443
**Note**: Pester tests always force-import the module from the output location of `.\build.ps1`.
5544

appveyor.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ install:
99
init:
1010
- git config --global core.autocrlf true
1111

12-
before_build:
13-
- nuget restore
14-
1512
build_script:
1613
- ps: |
1714
$ErrorActionPreference = 'Stop'
1815
Update-Help # we need up-to-date help content for tests
1916
.\build.ps1 -Configuration Release
2017
18+
test_script:
19+
- dotnet test .\test\Markdown.MAML.Test
20+
2121
after_test:
2222
- ps: |
2323
# We run Pester tests in after_test step
24-
# we don't want to use test_script so Xunit tests just run
24+
# we don't want to use test_script
2525
# appveyor doesn't run after_test, if tests failed.
2626
#
2727
# Pester tests produce artifacts in .\out directory

build.ps1

Lines changed: 32 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,102 +6,65 @@
66
param(
77
[ValidateSet('Debug', 'Release')]
88
$Configuration = "Debug",
9-
[switch]$SkipDocs
9+
[switch]$SkipDocs,
10+
[string]$DotnetCli
1011
)
1112

12-
# Attempts to find the (verified to exist) path to msbuild.exe; returns an empty string if
13-
# not found.
14-
function Find-MsBuildPath()
13+
function Find-DotnetCli()
1514
{
16-
[string] $msbuildPath = ''
17-
18-
$msbuildCmd = Get-Command -Name msbuild -ErrorAction Ignore
19-
20-
if ($msbuildCmd) {
21-
$msbuildPath = $msbuildCmd.Path
22-
} else {
23-
Write-Warning 'Searching for msbuild'
24-
25-
# For more info on vswhere.exe:
26-
# https://blogs.msdn.microsoft.com/heaths/2017/02/25/vswhere-available/
27-
# https://github.com/Microsoft/vswhere/wiki/Find-MSBuild
28-
$vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
29-
if (Test-Path $vswherePath) {
30-
31-
$vsInstallPath = & $vswherePath -latest `
32-
-requires Microsoft.VisualStudio.Component.Roslyn.Compiler, Microsoft.Component.MSBuild `
33-
-property installationPath
34-
35-
if (($LASTEXITCODE -eq 0) -and $vsInstallPath) {
36-
$msbuildPath = Join-Path $vsInstallPath 'MSBuild\15.0\Bin\MSBuild.exe'
37-
}
38-
}
39-
40-
if ($msbuildPath -and (-not (Test-Path $msbuildPath))) {
41-
$msbuildPath = ''
42-
}
43-
}
44-
45-
return $msbuildPath
15+
[string] $DotnetCli = ''
16+
$dotnetCmd = Get-Command dotnet
17+
return $dotnetCmd.Path
4618
}
4719

4820

49-
# build .dll
50-
[string] $msbuildPath = Find-MsBuildPath
51-
52-
if (-not $msbuildPath) {
53-
throw "I don't know where msbuild is."
21+
if (-not $DotnetCli) {
22+
$DotnetCli = Find-DotnetCli
5423
}
5524

56-
if (-not (Get-ChildItem "$PSScriptRoot\packages\*" -ErrorAction Ignore)) {
57-
# No packages... better restore or things won't go well.
58-
59-
$nugetCmd = 'nuget'
60-
if (-not (Get-Command -Name $nugetCmd -ErrorAction Ignore)) {
61-
$nugetCmd = "$PSScriptRoot\.nuget\NuGet.exe"
62-
}
63-
64-
Write-Host -Foreground Cyan 'Attempting nuget package restore'
65-
66-
try
67-
{
68-
Push-Location $PSScriptRoot
25+
if (-not $DotnetCli) {
26+
throw "dotnet cli is not found in PATH, install it from https://docs.microsoft.com/en-us/dotnet/core/tools"
27+
} else {
28+
Write-Host "Using dotnet from $DotnetCli"
29+
}
6930

70-
& $nugetCmd restore
71-
}
72-
finally
73-
{
74-
Pop-Location
75-
}
31+
if (Get-Variable -Name IsCoreClr -ValueOnly -ErrorAction SilentlyContinue) {
32+
$framework = 'netstandard1.6'
33+
} else {
34+
$framework = 'net451'
7635
}
7736

78-
& $msbuildPath Markdown.MAML.sln /p:Configuration=$Configuration
79-
$assemblyPaths = ((Resolve-Path "src\Markdown.MAML\bin\$Configuration\Markdown.MAML.dll").Path, (Resolve-Path "src\Markdown.MAML\bin\$Configuration\YamlDotNet.dll").Path)
37+
& $DotnetCli publish ./src/Markdown.MAML -f $framework --output=$pwd/publish /p:Configuration=$Configuration
38+
39+
$assemblyPaths = (
40+
(Resolve-Path "publish/Markdown.MAML.dll").Path,
41+
(Resolve-Path "publish/YamlDotNet.dll").Path
42+
)
8043

8144
# copy artifacts
82-
mkdir out -ErrorAction SilentlyContinue > $null
83-
cp -Rec -Force src\platyPS out
45+
New-Item -Type Directory out -ErrorAction SilentlyContinue > $null
46+
Copy-Item -Rec -Force src\platyPS out
8447
foreach($assemblyPath in $assemblyPaths)
8548
{
8649
$assemblyFileName = [System.IO.Path]::GetFileName($assemblyPath)
8750
$outputPath = "out\platyPS\$assemblyFileName"
8851
if ((-not (Test-Path $outputPath)) -or
89-
(Test-Path $outputPath -OlderThan (ls $assemblyPath).LastWriteTime))
52+
(Test-Path $outputPath -OlderThan (Get-ChildItem $assemblyPath).LastWriteTime))
9053
{
91-
cp $assemblyPath out\platyPS
54+
Copy-Item $assemblyPath out\platyPS
9255
} else {
9356
Write-Host -Foreground Yellow "Skip $assemblyFileName copying"
9457
}
9558
}
9659

9760
# copy schema file and docs
98-
cp .\platyPS.schema.md out\platyPS
99-
mkdir out\platyPS\docs -ErrorAction SilentlyContinue > $null
100-
cp .\docs\* out\platyPS\docs\
61+
Copy-Item .\platyPS.schema.md out\platyPS
62+
New-Item -Type Directory out\platyPS\docs -ErrorAction SilentlyContinue > $null
63+
Copy-Item .\docs\* out\platyPS\docs\
10164

10265
# copy template files
103-
mkdir out\platyPS\templates -ErrorAction SilentlyContinue > $null
104-
cp .\templates\* out\platyps\templates\
66+
New-Item -Type Directory out\platyPS\templates -ErrorAction SilentlyContinue > $null
67+
Copy-Item .\templates\* out\platyPS\templates\
10568

10669
# put the right module version
10770
if ($env:APPVEYOR_REPO_TAG_NAME)

src/Markdown.MAML/App.config

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)