Skip to content

Commit

Permalink
Auto patch file version on AppVeyor
Browse files Browse the repository at this point in the history
  • Loading branch information
304NotModified committed Oct 19, 2017
1 parent 4113785 commit 5ee1085
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ build_script:
- ps: >-
dotnet restore src\NLog.Extensions.Logging
.\patchFileVersion.ps1 "NLog.Extensions.Logging.csproj" "$env:appveyor_build_version"
dotnet pack src\NLog.Extensions.Logging --configuration Release
artifacts:
- path: 'src\NLog.Extensions.Logging\bin\release\*.nupkg'
Expand Down
42 changes: 42 additions & 0 deletions patchFileVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
param([string]$filewildCard, [string]$version)

#returns FileInfo
function findFile([string]$filewildCard) {

$files = @(Get-ChildItem $filewildCard -Recurse);
if ($files.Length -gt 1) {
throw "Found $($files.length) files. Stop, we need an unique pattern"
}
if ($files.Length -eq 0) {
throw "Find not found with pattern $filewildCard. Stop"
}
return $files[0];
}

function patchAssemblyFileVersion([System.IO.FileInfo]$file , [string]$version) {

$xmlPath = $file.FullName;

$xml = [xml](get-content $xmlPath)

$propertyGroup = $xml.Project.PropertyGroup

Write-Host "patch $xmlPath to $version"

# FileVersion = AssemblyFileVersionAttribute
$propertyGroup[0].FileVersion = $version

$xml.Save($xmlPath)
}

$file = findFile $filewildCard -ErrorAction Stop

patchAssemblyFileVersion $file $version -ErrorAction Stop



trap
{
write-output $_
exit 1
}
5 changes: 5 additions & 0 deletions src/NLog.Extensions.Logging/NLog.Extensions.Logging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ rc2 (see https://github.com/NLog/NLog.Extensions.Logging/milestone/9?closed=1)
<RepositoryType>git</RepositoryType>
<RepositoryUrl>git://github.com/NLog/NLog.Extensions.Logging</RepositoryUrl>
<Version>1.0.0-rtm-rc2</Version>

<AssemblyVersion>1.0.0.0</AssemblyVersion>
<!--AssemblyVersion: keep 1.0.0.0-->
<FileVersion>1.0.0.0</FileVersion>
<!-- FileVersion = AssemblyFileVersionAttribute, patched by AppVeyor -->
</PropertyGroup>

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

0 comments on commit 5ee1085

Please sign in to comment.