2012-03-08 60 views
0

我试图找到使用Powershell,部署的Sharepoint解决方案的AssemblyFileVersion。从GetReferencedAssemblies获取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),但它不起作用。我认为这是一个共享点解决方案,因为它对此产生影响。

回答

2

我正在寻找一个解决方案,并找到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缓存在那里,以便它最终结束:)

+0

感谢您的帮助。我尝试过但它不起作用。问题是Sharepoint解决方案中的引用程序集不会发布到GAC。所以当ReflectionOnlyLoad命中他们时,他们不在那里,是给出了“无法加载文件或程序集”错误。我可以发布到GAC,但我试图找到一种方法来不改变现有的项目 – 2012-03-09 14:13:53

+0

好吧,在已知文件夹中的程序集?我问,因为如果你知道位置,你可以加载它们并只过滤那些被引用的。 – stej 2012-03-09 15:42:39

+0

他们可能是,但它可能是在诙谐的Sharepoint Wive – 2012-03-09 16:14:03

0

System.Reflection.AssemblyFileVersionAttribute是一个自定义属性。使用此API:

ps> $assembly = [System.Reflection.Assembly]::LoadWithPartialName("<AssemblyName>") 
ps> $attr = $assembly.getcustomattributes(
     [reflection.assemblyfileversionattribute])[0] 
ps> $attr.version 
1.0.4.1