有没有办法减轻维护.NET程序集引用的痛苦?

有没有办法减轻维护.NET程序集引用的痛苦?,.net,asp.net,reflection,assemblies,metadata,.net,Asp.net,Reflection,Assemblies,Metadata,我目前正在从事一个涉及多个程序集的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项目造成严重破

我目前正在从事一个涉及多个程序集的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项目造成严重破坏,因为它包含大量ASP.NET页面和母版页,它们引用程序集a和B中的类型

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


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

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


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

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


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

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

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


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

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

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


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

结果我发现了一个博客,描述了一种使用OrtoiseSVN附带的subwcrev工具将1.0.0.$REV$替换为1.0.0.25或其他什么的方法。这正是我想要的。这是明智的。

结果我发现了一个博客,描述了一种使用TortoiseSVN附带的subwcrev工具将1.0.0.$REV$替换为1.0.0.25或任何东西的方法。这正是我想要的。这是明智的。

我使用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 ;
}
#SetVersion.ps1
#
#在任何子目录中的所有AssemblyInfo.cs或AssemblyInfo.vb文件中设置版本。
#
#用法:
#从cmd.exe:
#powershell.exe SetVersion.ps1 2.8.3.0
# 
#从powershell.exe提示符:
#.\SetVersion.ps1 2.8.3.0
#
#上次保存的时间戳:
#
功能使用
{
回声“用法:”;
echo“来自cmd.exe:”;
echo“powershell.exe SetVersion.ps1 2.8.3.0”;
回声“;
echo“来自powershell.exe提示符:”;
echo“\SetVersion.ps1 2.8.3.0”;
回声“;
}
函数更新SourceVersion
{
参数([string]$Version)
$NewVersion='AssemblyVersion(“+$Version+”);
$NewFileVersion='AssemblyFileVersion(“+$Version+”);
foreach($o单位为$input)
{
####!!如有必要,在此处执行版本控制签出
写入输出$o.FullName
$TmpFile=$o.FullName+“.tmp”
获取内容$o.FullName |
%{$\替换'AssemblyVersion\(“[0-9]+(\.([0-9]+\*){1,3}”\”,$NewVersion}|
%{$\替换'AssemblyFileVersion\(“[0-9]+(\.([0-9]+\*){1,3}”\”,$NewFileVersion}>$TmpFile
移动项目$TmpFile$o.FullName-强制
}
}
函数更新AllAssemblyInfoFiles($version)
{
foreach(“AssemblyInfo.cs”、“AssemblyInfo.vb”中的文件)
{
get childitem-recurse |?{$|.Name-eq$file}更新SourceVersion$version;
}
}
#验证参数
$r=[System.Text.RegularExpressions.Regex]::匹配($args[0],“^[0-9]+(\[0-9]+){1,3}$”;
如果($r.Success)
{
更新AllAssemblyInfoFiles$args[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 ;
}
#SetVersion.ps1
#
#在任何子目录中的所有AssemblyInfo.cs或AssemblyInfo.vb文件中设置版本。
#
#用法:
#从cmd.exe:
#powershell.exe SetVersion.ps1 2.8.3.0
# 
#从powershell.exe提示符:
#.\SetVersion.ps1 2.8.3.0
#
#上次保存的时间戳:
#
功能使用
{
回声“用法:”;
echo“来自cmd.exe:”;
echo“powershell.exe SetVersion.ps1 2.8.3.0”;
回声“;
echo“来自powershell.exe提示符:”;
echo“\SetVersion.ps1 2.8.3.0”;
回声“;
}
函数更新SourceVersion
{
参数([string]$Version)
$NewVersion='AssemblyVersion(“+$Version+”);
$NewFi