【问题标题】:View current Assembly Version number within VS2008在 VS2008 中查看当前的程序集版本号
【发布时间】:2010-10-12 17:03:20
【问题描述】:

我想知道是否有办法在 Visual Studio 2008 IDE 中查看上次完成构建的程序集版本号。我不想看到 Assembly Information 对话框或 AssemblyInfo 文件中的 1.0.*,而是看到完整版本(* 替换为实数)。我也不想调出项目可执行文件或程序集的属性。

【问题讨论】:

    标签: .net visual-studio-2008 assemblies versioning


    【解决方案1】:
    Assembly.GetExecutingAssembly().FullName.
    

    来自MSDN

    using System;
    using System.Reflection;
    
    class Example
    {
        static void Main()
        {
            Console.WriteLine("The FullName property (also called the display name) of...");
            Console.WriteLine("...the currently executing assembly:");
            Console.WriteLine(Assembly.GetExecutingAssembly().FullName);
    
            Console.WriteLine("...the assembly that contains the Int32 type:");
            Console.WriteLine(typeof(int).Assembly.FullName);
        }
    }
    
    /* This example produces output similar to the following:
    
    The FullName property (also called the display name) of...
    ...the currently executing assembly:
    SilverlightApplication, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
    ...the assembly that contains the Int32 type:
    mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
     */
    

    【讨论】:

      【解决方案2】:

      一种简化的方法,

      Application.ProductName;
      Application.ProductVersion;
      

      【讨论】:

        【解决方案3】:

        属性中的 Assembly Info 框指向项目中的一个文件,通常称为 AssemblyInfo.cs(在 Properties 文件夹中)。这就是设置版本的实际代码所在的位置,查看该文件可能比浏览设置更容易。

        编辑
        现在我明白了这个问题。这是一个生成的数字,不会以我知道的任何方式通过 Visual Studio 公开。

        编辑 2
        如果您愿意依赖 PowerShell,您可以创建一个构建后事件或 External Tools menu item 来调用该程序集上的 .NET 方法以获取其版本...

        【讨论】:

        • 如果设置框中有星号,则 AssemblyInfo.cs 中也有星号。
        【解决方案4】:

        好的,我想我现在更好地解决了您的问题,您想查看内部版本号是什么,而无需实际构建...如,Visual Studio 如何知道下一个数字将是什么,当其设置为 * ?

        如果您使用自动构建编号,假设您有 1.0.* 并且 VS 构建一个值,例如 1.0.3245.1234

        3245 是自 2000 年 1 月 1 日以来的天数

        1234 是自午夜以来的秒数,除以二。

        回答您的编辑:

        我唯一能想到的在不执行程序集内的某些代码或检查文件属性的情况下获取内部版本号的方法是进行某种构建后事件,该事件检查程序集的属性并弹出一个显示它的消息框,或者更好的是,使用内部版本号在 AssemblyInfo.cs 文件的顶部写一条注释

        【讨论】:

        • 我已经澄清了我的问题。我想要的是能够看到构建后的内部版本号,并通过 IDE 进行。
        【解决方案5】:

        我建议对您的构建过程进行一些小改动,以便每次编译时都会在输出区域中显示版本号。其实很简单:

        右键单击您的项目并选择“卸载项目”。您的所有代码都“消失”了,但不必惊慌。

        再次右键单击它,然后选择“编辑...”。 这会以 xml 格式打开 proj 文件,您现在可以在 <ProjectExtensions> 标记内添加这段代码的 sn-p。

        <Target Name="AfterBuild">
          <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
            <Output TaskParameter="Assemblies" ItemName="MyAssemblyIdentities"/>
          </GetAssemblyIdentity>
          <Message Text="AssemblyVersion: %(MyAssemblyIdentities.Version)" 
            Importance="high" />
        </Target>
        

        保存并关闭文件。右键单击并选择“重新加载项目”。这将像以前一样恢复项目。

        编译,你会在输出窗口中看到一个新的文本行:

        AssemblyVersion = 1.0.3518.36887

        就是这样。

        正是这一集的 DnrTV,Sayed Hashimi on MS Build,让我对 MSBuild 和所有你能做的很酷的事情大开眼界。强烈推荐。 :)

        【讨论】:

          猜你喜欢
          • 2023-03-19
          • 1970-01-01
          • 2020-09-03
          • 2011-05-08
          • 1970-01-01
          • 1970-01-01
          • 2010-12-31
          • 2012-05-21
          • 1970-01-01
          相关资源
          最近更新 更多