-
Notifications
You must be signed in to change notification settings - Fork 252
/
configure.ps1
87 lines (64 loc) · 2.34 KB
/
configure.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#/usr/bin/env pwsh
<#
.SYNOPSIS
Configure Sample projects build properties (Directory.Build.props).
.DESCRIPTION
Sync Directory.Build.props in project folder with "main" config/Directory.Build.props file.
Project should reference to any Steeltoe package with Version=$(SteeltoeVersion).
#>
$currentDirectory = Get-Location
# props file path to copy into sample projects
$propsFilePath = "./config/Directory.Build.props"
# copy props file only into samples which refers to Steeltoe libraries
$libraryReference = '$(SteeltoeVersion)'
function multitarget() {
Write-Host 'multitarget projects...'
try
{
Set-Location $PSScriptRoot
$multitargets = '<TargetFrameworks>';
$dirsToSync = Get-ChildItem *.csproj -Recurse |
where { $_ | Select-String -SimpleMatch $multitargets } |
Select-String -SimpleMatch $libraryReference -List | Select Path | Split-Path
foreach ($dir in $dirsToSync)
{
Write-Host $dir
Copy-Item $propsFilePath $dir -Force
}
}
finally
{
Set-Location $currentDirectory
}
}
function net6only() {
Write-Host 'net 6.0 only projects...'
try
{
Set-Location $PSScriptRoot
$target6_0_only = '<TargetFramework>net6.0</TargetFramework>';
$dirsToSync = Get-ChildItem *.csproj -Recurse |
where { $_ | Select-String -SimpleMatch $target6_0_only } |
Select-String -SimpleMatch $libraryReference -List | Select Path | Split-Path
$propsAsXml = [xml](Get-Content $propsFilePath)
$frameworkCondition = '''$(TargetFramework)'' == ''net6.0'''
$propsAsXml.SelectNodes("//Project/PropertyGroup[@Condition != """ + $frameworkCondition + """]") |
Foreach-Object {
$_.ParentNode.RemoveChild($_)
}
#$propsAsXml.SelectSingleNode("//Project/PropertyGroup[@Condition = """ + $frameworkCondition + """]").Attributes.RemoveNamedItem("Condition");
$propsFileName = Split-Path $propsFilePath -leaf
foreach ($dir in $dirsToSync)
{
Write-Host $dir
$pathToProjectProps = Join-Path -Path $dir -ChildPath $propsFileName
$propsAsXml.Save($pathToProjectProps)
}
}
finally
{
Set-Location $currentDirectory
}
}
multitarget
net6only