0

我目前正在开发一个涉及多个程序集的 Web 项目,其结构如下:

WebProject
 |
 +--> A (external assembly, Version 1.0.0.0)
 |
 +--> B (external assembly, Version 1.0.0.0)

困难在于,为了跟踪部署的内容,我想在每次构建时更新程序集 A 和 B 的版本号。现在我正在使用该[assembly: AssemblyVersion("1.0.*")]技术进行此操作,但它在 WebProject 项目中造成严重破坏,因为它包含许多引用程序集 A 和 B 中的类型的 ASP.NET 页面和母版页。

除了手动更新这些引用之外,还有更简单的方法吗?

更新:程序集 A 和 B 存在于一个解决方案中,而 WebProject 存在于另一个解决方案中。此外,A 和 B 被强烈命名,因为它们被部署到 IIS/SharePoint 服务器。

4

5 回答 5

1

您是否直接引用已编译的程序集?考虑将它们添加到您的解决方案中,并将它们作为项目参考。

如果你做得对,这也适用于多个应用程序使用的程序集,因为每个“父”解决方案都可以包含引用。当然,这导致了不可避免的挑战,即了解“此更改是否会破坏任何其他应用程序”,这需要大量计划。通过对接口和/或抽象类进行编码并将无法通过重载完成的任何签名更改视为“破坏性更改”,从而需要对使用这些程序集的其他应用程序进行回归,可以稍微缓解这个问题。

于 2009-03-26T18:10:20.527 回答
1

对于同一解决方案中的项目引用,这是自动完成的。

如果 A 和 B 不在同一个解决方案中,那么您可以将它们的引用设置为不需要特定版本(查看引用属性) - 但请注意,这仅用于编译时,因此您仍然需要重新编译A 或 B 更新时的 web 项目。

如果失败,您可能会查看程序集绑定重定向。

于 2009-03-26T18:11:24.860 回答
1

在 Cedaron 的构建过程中,我们通过构建脚本将它们复制到 Web 项目的 bin 目录中来维护 Web 项目中的引用,而不是声明引用。

你不会认为这会奏效,但它确实有效。如果它们在 bin 目录中,则可以使用它们。

于 2009-05-12T17:29:17.960 回答
0

结果我发现了一个博客,描述了一种使用 TortoiseSVN 附带的 subwcrev 工具将 1.0.0.$REV$ 替换为 1.0.0.25 或其他内容的方法。这几乎是我想要的。这是理智的。

于 2009-04-24T20:24:26.127 回答
0

我使用 powershell 脚本来做同样的事情,独立于 SVN 或任何特定版本控制系统的使用。

# SetVersion.ps1
#
# Set the version in all the AssemblyInfo.cs or AssemblyInfo.vb files in any subdirectory.
#
# usage:  
#  from cmd.exe: 
#     powershell.exe SetVersion.ps1  2.8.3.0
# 
#  from powershell.exe prompt: 
#     .\SetVersion.ps1  2.8.3.0
#
# last saved Time-stamp: <2009-February-11 22:18:04>
#


function Usage
{
  echo "Usage: ";
  echo "  from cmd.exe: ";
  echo "     powershell.exe SetVersion.ps1  2.8.3.0";
  echo " ";
  echo "  from powershell.exe prompt: ";
  echo "     .\SetVersion.ps1  2.8.3.0";
  echo " ";
}


function Update-SourceVersion
{
  Param ([string]$Version)

  $NewVersion = 'AssemblyVersion("' + $Version + '")';
  $NewFileVersion = 'AssemblyFileVersion("' + $Version + '")';

  foreach ($o in $input) 
  {

    #### !! do Version control checkout here if necessary 
    Write-output $o.FullName
    $TmpFile = $o.FullName + ".tmp"

     get-content $o.FullName | 
        %{$_ -replace 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewVersion } |
        %{$_ -replace 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewFileVersion }  > $TmpFile

     move-item $TmpFile $o.FullName -force
  }
}


function Update-AllAssemblyInfoFiles ( $version )
{
  foreach ($file in "AssemblyInfo.cs", "AssemblyInfo.vb" ) 
  {
    get-childitem -recurse |? {$_.Name -eq $file} | Update-SourceVersion $version ;
  }
}


# validate arguments 
$r= [System.Text.RegularExpressions.Regex]::Match($args[0], "^[0-9]+(\.[0-9]+){1,3}$");

if ($r.Success)
{
  Update-AllAssemblyInfoFiles $args[0];
}
else
{
  echo " ";
  echo "Bad Input!"
  echo " ";
  Usage ;
}
于 2009-05-12T17:11:50.393 回答