组装信息版本信息以星号表示

本文关键字:信息 表示 版本 | 更新日期: 2023-09-27 18:31:34

它在AssemblyInfo中说.cs对于C#项目,可以使用*指定版本信息

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

我把它改成这样:

[assembly: AssemblyVersion("1.0.*.*")]
[assembly: AssemblyFileVersion("1.0.*.*")]

这是我从编译器得到的错误:

error CS0647: Error emitting 'System.Reflection.AssemblyVersionAttribute' attribute -- 'The version specified '1.0.*.*' is invalid'
warning CS1607: Assembly generation -- The version '1.0.*.*' specified for the 'file version' is not in the normal 'major.minor.build.revision' format

它是如何工作的(甚至吗?

组装信息版本信息以星号表示

"automatic" 内部版本号的语法(请参阅 MSDN)可以是:

[assembly: AssemblyVersion("1.0.0.*")]

或:

[assembly: AssemblyVersion("1.0.*")]

* 表示在此之后一切都是自动的。您不能有自动内部版本号和固定修订版号,则此语法不正确:

[assembly: AssemblyVersion("1.0.*.0")]

对于AssemblyFileVersionAttribute,您不能使用 * 特殊字符,因此您必须提供完整且有效的版本号。请注意,如果您不提供AssemblyFileVersionAttribute则会自动获得正确的FileVersionInfo(使用相同版本的AssemblyVersionAttribute)。仅当需要设置其他版本时,才需要指定该属性。

[assembly: AssemblyVersion("1.0.*")] 
//[assembly: AssemblyFileVersion("1.0.*")] 

只要记得注释 AssemblyFileVersion 行,否则自动生成的汇编版本将始终为 "1.0.0.0"。

那么为什么提供的评论说

// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]

但是构建生成CS8357?有人没有收到备忘录。

Work around:
 1. Close all open documents
 2. In the Solution Explorer, right-click the Project and select Unload Project
 3. In the Solution Explorer, right-click the Project (now marked as unavailable) and select Edit to access the `.CSPROJ` file
 4. In the opened window, find `<Deterministic>true</Deterministic>` and change it to `<Deterministic>false</Deterministic>`
 5. Save the file and ensure that the edit window is closed
 6. In the Solution Explorer, right-click the Project and select Reload Project
Your build (should then) work. :)

在我看来,使用 [assembly: AssemblyVersion("x.y.z.*")]Patch不应该自动编号。例如:

[汇编:汇编版本("1.2.3.*")]

AssemblyVersion中使用"*"很好,但按照 seemver.org 我们应该对版本结构<major version>.<minor version>.<build number>.<revision>中的revision部分使用 * )。

给定版本号 MAJOR。次要。补丁,递增:

当您进行不兼容的 API 更改时的主要版本,

以向后兼容的方式添加功能时的次要版本,以及

PATCH 版本,当您进行向后兼容的错误修复时。

我在版本中使用了"*"到易于控制的版本,并为客户提供信息。我有一个在手持设备(PointOfSell)中运行的小程序,有时会更新。:-)在我的代码中,我使用:

程序集信息片段.cs

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.*")]
// Need to comment this line, 
//[assembly: AssemblyFileVersion("1.0.0.0")]
//to avoid the following error:
// ...'Properties'AssemblyInfo.cs(36,32,36,39):
// warning CS7035: The specified version string does not conform to 
// the recommended format - major.minor.build.revision
// warning AL1053: The version '1.0.*' specified for 
// the 'file version' is not in the normal 'major.minor.build.revision' format

检查更新时,我从小型 Web 服务向客户端发送版本列表。

void smsReceive1_OnCabUpdate(object sender, CabDataEventArgs e)
{
    try
    {
        var cabVer = e.CabVersion;
        var sms1 = (SmsService.SmsService)sender;
        SmsService.CabinetVersion progVer = null;
        var exeApp = Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
        foreach (var item in cabVer)
        {
            if (string.Compare(item.FileName, exeApp, true) == 0)
            {
                progVer = item;
                break;
            }
        }
        var msgForm = new MessageBoxForm();
        if (!forceUpdate && !WillUpdateVersion(progVer))
        {
            Buzzer.Warning();
            sms1.StopReceive();
            msgForm.Message = "'r'nNewest Version!'r'n" +
                "Version'r'n" + progVer.AssemblyVersion.ToString() + "'r'n" +
                "Last Modified:'r'n" + progVer.AssemblyVersion.ToDateTime().ToString("yy/MM/dd HH:mm") + "'r'n" +
                "'r'nNo need to update";
            msgForm.OKShowDialog();
            return;
        }
        // 
        byte[] buffer = e.CabData;
        var filename = "''ramdisk''Setup.cab";
        if (File.Exists(filename))
        {
            File.Move(filename, string.Format("{0:yyMMdd_HHmmss}_Setup.cab"));
        }
        var fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
        fs.Write(buffer, 0, buffer.Length);
        fs.Flush();
        fs.Close();
        //
        Buzzer.Warning();
        //Stop SmsReceive
        sms1.StopReceive();
        msgForm.Message = "There is an update.'r'n" +
            "Version 'r'n" + progVer.AssemblyVersion.ToString() + "'r'n" +
            "Last Modified:'r'n" + progVer.AssemblyVersion.ToDateTime().ToString("yy/MM/dd HH:mm") + "'r'n" +
            "※After the update'r'nIt will restart automatically";
        msgForm.SetSubMessage("Do you want to update?");
        var resp = msgForm.OKCancelShowDialog(true) == DialogResult.OK;
        if (resp)
        {
            CabFileUpdatePath = filename;
            UpdateApplication = true;
            Invoke((Action)(() => restartApplicationTimer.Enabled = true));
        }
        else
        {
            File.Delete(filename);
        }
    }
    finally
    {
        if (smsReceive1 != null) smsReceive1.ServicePaused = ServiceStatus.None;
    }
}
private bool WillUpdateVersion(SmartShooter.SmsService.CabinetVersion ver)
{
    var appVer = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
    if (ver.CompareToExe(appVer) > 0) return true;
    return false;
}

progVer.AssemblyVersion.ToDateTime().ToString("yy/MM/dd HH:mm")

最后,这是因为我在版本中使用了"*"。

public partial class MyVersion {
    
    public ushort Build { get; set; }
    
    public ushort Major { get; set; }
    
    public ushort Minor { get; set; }
    
    public ushort Revision { get; set; }
    
    public override string ToString()
    {
        return string.Format("{0}.{1}.{2}.{3}", Major, Minor, Build, Revision);
    }
    public DateTime ToDateTime()
    { 
        var dt = new DateTime(2000, 1, 1, 0, 0, 0);
        //plus days
        dt = dt.AddDays(Build);
        //plus seconds
        dt = dt.AddSeconds(Revision * 2);
        return dt;
    }
}

我使用"构建"值来查找项目编译的日期,并使用"修订"来获取精确的小时。