其他分享
首页 > 其他分享> > 新版本(AssemblyFileVersionAttribute.Version)总是会成功吗?

新版本(AssemblyFileVersionAttribute.Version)总是会成功吗?

作者:互联网

新版本(AssemblyFileVersionAttribute.Version)会永远成功吗?

这是我的代码.

Contract.Ensures(Contract.Result<Version>() != null);
var ass = Assembly.GetExecutingAssembly();
var attributes = ass.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false).Cast<AssemblyFileVersionAttribute>();
var versionAttribute = attributes.Single();
return new Version(versionAttribute.Version)

解决方法:

没有:

[assembly:AssemblyFileVersion("fred")]
static class program
{
    static void Main()
    {
        var ass = Assembly.GetExecutingAssembly();
        var attributes = ass.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false).Cast<AssemblyFileVersionAttribute>();
        var versionAttribute = attributes.Single();
        var ver = new Version(versionAttribute.Version);        
    }
}

请注意,这确实会产生警告:

Warning 1 Assembly generation — The version ‘Fred’ specified for the ‘file version’ is not in the normal ‘major.minor.build.revision’ format

但是警告并不能阻止它的发生.

标签:net-assembly,c,net
来源: https://codeday.me/bug/20191123/2066773.html