Skip to content

Commit c8165fa

Browse files
Merge pull request #162 from NLog/patch-file-version
Auto patch file version on AppVeyor
2 parents ffee282 + 5ee1085 commit c8165fa

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ build_script:
44
- ps: >-
55
dotnet restore src\NLog.Extensions.Logging
66
7+
.\patchFileVersion.ps1 "NLog.Extensions.Logging.csproj" "$env:appveyor_build_version"
8+
79
dotnet pack src\NLog.Extensions.Logging --configuration Release
810
artifacts:
911
- path: 'src\NLog.Extensions.Logging\bin\release\*.nupkg'

patchFileVersion.ps1

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
param([string]$filewildCard, [string]$version)
2+
3+
#returns FileInfo
4+
function findFile([string]$filewildCard) {
5+
6+
$files = @(Get-ChildItem $filewildCard -Recurse);
7+
if ($files.Length -gt 1) {
8+
throw "Found $($files.length) files. Stop, we need an unique pattern"
9+
}
10+
if ($files.Length -eq 0) {
11+
throw "Find not found with pattern $filewildCard. Stop"
12+
}
13+
return $files[0];
14+
}
15+
16+
function patchAssemblyFileVersion([System.IO.FileInfo]$file , [string]$version) {
17+
18+
$xmlPath = $file.FullName;
19+
20+
$xml = [xml](get-content $xmlPath)
21+
22+
$propertyGroup = $xml.Project.PropertyGroup
23+
24+
Write-Host "patch $xmlPath to $version"
25+
26+
# FileVersion = AssemblyFileVersionAttribute
27+
$propertyGroup[0].FileVersion = $version
28+
29+
$xml.Save($xmlPath)
30+
}
31+
32+
$file = findFile $filewildCard -ErrorAction Stop
33+
34+
patchAssemblyFileVersion $file $version -ErrorAction Stop
35+
36+
37+
38+
trap
39+
{
40+
write-output $_
41+
exit 1
42+
}

src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ rc2 (see https://github.com/NLog/NLog.Extensions.Logging/milestone/9?closed=1)
2828
<RepositoryType>git</RepositoryType>
2929
<RepositoryUrl>git://github.com/NLog/NLog.Extensions.Logging</RepositoryUrl>
3030
<Version>1.0.0-rtm-rc2</Version>
31+
32+
<AssemblyVersion>1.0.0.0</AssemblyVersion>
33+
<!--AssemblyVersion: keep 1.0.0.0-->
34+
<FileVersion>1.0.0.0</FileVersion>
35+
<!-- FileVersion = AssemblyFileVersionAttribute, patched by AppVeyor -->
3136
</PropertyGroup>
3237

3338
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">

0 commit comments

Comments
 (0)