首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从GetReferencedAssemblies获取AssemblyFileVersion

从GetReferencedAssemblies获取AssemblyFileVersion
EN

Stack Overflow用户
提问于 2012-03-09 01:32:25
回答 2查看 816关注 0票数 0

我正在尝试使用Powershell查找已部署的Sharepoint解决方案的AssemblyFileVersion。

到目前为止,我设法找到了关于解决方案本身的信息,但现在我正在尝试找到关于它的参考资料的相同信息。

有没有办法获取这些数据。

到目前为止,我的代码如下

代码语言:javascript
复制
$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解决方案对此的影响。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-09 18:47:34

我正在寻找一个解决方案,并找到可能对您有帮助的ReflectionOnlyLoad方法。

代码语言:javascript
复制
$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缓存在那里,所以它最终结束了:)

票数 2
EN

Stack Overflow用户

发布于 2012-03-10 10:37:49

System.Reflection.AssemblyFileVersionAttribute是一个自定义属性。使用本接口:

代码语言:javascript
复制
ps> $assembly = [System.Reflection.Assembly]::LoadWithPartialName("<AssemblyName>")
ps> $attr = $assembly.getcustomattributes(
       [reflection.assemblyfileversionattribute])[0]
ps> $attr.version
1.0.4.1
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9622085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档