我正在尝试使用Powershell查找已部署的Sharepoint解决方案的AssemblyFileVersion。
到目前为止,我设法找到了关于解决方案本身的信息,但现在我正在尝试找到关于它的参考资料的相同信息。
有没有办法获取这些数据。
到目前为止,我的代码如下
$assembly = [System.Reflection.Assembly]::LoadWithPartialName("<AssemblyName>")
$fvi = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($assembly.Location)
Write-Host "File Version Number " $fvi.ProductVersion
$references = $assembly.GetReferencedAssemblies();
foreach ($ref in $references)
{
Write-Host $ref.Version
}$ref.Version返回不同的AssemblyVersion。
我尝试了相同的方法([System.Reflection.Assembly]::LoadWithPartialName),但它不起作用。我猜想这是一个sharepoint解决方案对此的影响。
发布于 2012-03-09 18:47:34
我正在寻找一个解决方案,并找到可能对您有帮助的ReflectionOnlyLoad方法。
$processed = @{}
function writeAssemblyFileVersions {
param($parentAssemblyPath)
if ($processed[$parentAssemblyPath]) {
return
}
$processed.$parentAssemblyPath = 1
$ver = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($parentAssemblyPath).ProductVersion
$assembly = [reflection.assembly]::LoadFile($parentAssemblyPath)
Write-Output (New-Object PsObject -Property @{Version = $ver; Assembly = $assembly})
foreach($a in $assembly.GetReferencedAssemblies()) {
$aForLocation = [Reflection.Assembly]::ReflectionOnlyLoad($a.FullName)
writeAssemblyFileVersions $aForLocation.Location
}
}
###### sample
$loc = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms").Location
writeAssemblyFileVersions $loc |
Select Version, {$_.Assembly.ManifestModule.Name}它递归地检查所有依赖项。$processed缓存在那里,所以它最终结束了:)
发布于 2012-03-10 10:37:49
System.Reflection.AssemblyFileVersionAttribute是一个自定义属性。使用本接口:
ps> $assembly = [System.Reflection.Assembly]::LoadWithPartialName("<AssemblyName>")
ps> $attr = $assembly.getcustomattributes(
[reflection.assemblyfileversionattribute])[0]
ps> $attr.version
1.0.4.1https://stackoverflow.com/questions/9622085
复制相似问题