Skąd wież, że wszystkie biblioteki w projekcie mają taką samą wersję lub nazwę produktu?
Ja napisałem mały skrypcik do walidacji biblioteczek pod względem wersji. Poniżej jest skrypt:
function Test-AssemblyVersion
{
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
[String]
$filePath
,
[Parameter(
ValueFromPipeline=$false)
]
[String]
$ProductVersion
,
[Parameter(
ValueFromPipeline=$false)
]
[String]
$FileVersion
)
begin{
$invIC= [System.StringComparison]::InvariantCultureIgnoreCase
}
process {
$file = $_
if(test-path $file)
{
$ass = [System.Reflection.Assembly]::LoadFile($file)
$fvi = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ass.Location)
if( $ProductVersion.Equals($fvi.ProductVersion, $invIC)
-and $FileVersion.Equals($fvi.FileVersion, $invIC) )
{
Write-Host "$file is ok."
}
else
{
throw "Wrong ProductVersion or FileVersion in $file."
}
}
}
}
Przykładowe wywołanie przedstawione jest poniżej:gci -path .\MyProject\bin\ -recurse -filter 'MyProject.*.dll' | Test-AssemblyVersion -ProductVersion 2.1.0.0 -FileVersion 2.1.0.0Można teraz dodać wywołanie i funkcję do jednego pliku i cały kod wyglądałby tak:
param(
[string]$ProductVersion,
[string]$FileVersion
)
function Test-AssemblyVersion
{
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
[ValidateNotNullOrEmpty()]
[String]
$filePath
,
[Parameter(
Position=1,
Mandatory=$true,
ValueFromPipeline=$false,
ValueFromPipelineByPropertyName=$false)
]
[ValidateNotNullOrEmpty()]
[String]
$ProductVersion
,
[Parameter(
Position=2,
Mandatory=$true,
ValueFromPipeline=$false,
ValueFromPipelineByPropertyName=$false)
]
[ValidateNotNullOrEmpty()]
[String]
$FileVersion
)
begin{
$invIC= [System.StringComparison]::InvariantCultureIgnoreCase
}
process {
$file = $_
if(test-path $file)
{
$ass = [System.Reflection.Assembly]::LoadFile($file)
$fvi = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($ass.Location)
if( $ProductVersion.Equals($fvi.ProductVersion, $invIC) -and $FileVersion.Equals($fvi.FileVersion, $invIC) )
{
Write-Host "$File is ok. ProductVersion is $($fvi.ProductVersion) and FileVersion is $($fvi.FileVersion)"
}
else
{
throw "Wrong ProductVersion or FileVersion in $file. ProductVersion is $($fvi.ProductVersion) and FileVersion is $($fvi.FileVersion)"
}
}
}
}
$root = ( gi '..\..' ).FullName
Write-host "Root is $root"
$OutputPackage = "$root\bin"
if(Test-path $OutputPackage)
{
$fcraLib = gci -path $OutputPackager -filter 'MyProject.*.dll'
if( $fcraLib)
{
$fcraLib | %{$_.Fullname} | Test-AssemblyVersion -ProductVersion $ProductVersion -FileVersion $FileVersion
}
else
{
throw "No dll files in dir: $OutputPackage "
}
}
Teraz można ten skrypt podpiąć do TeamCity.
Brak komentarzy:
Prześlij komentarz