C# AssemblyInfo 版本信息星号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10229711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 12:58:58  来源:igfitidea点击:

AssemblyInfo version information asterisks

c#.net

提问by mare

It says in AssemblyInfo.cs for C# projects that it's possible to specify version information with *

它在 C# 项目的 AssemblyInfo.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 Revision and Build Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

I changed it to this:

我把它改成这样:

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

and this is the error I get from the compiler:

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

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

How does (does it even?) it work?

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

采纳答案by Adriano Repetti

Syntax (see MSDN) for "automatic" build number can be:

“自动”内部版本号的语法(参见MSDN)可以是:

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

or:

或者:

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

*means after this everything is automatic. You can't have automatic build number and fixed revision number then this syntax isn't correct:

*意味着在这之后一切都是自动的。您不能拥有自动内部版本号和固定版本号,则此语法不正确:

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

For the AssemblyFileVersionAttributeyou cannot use the *special character so you have to provide a full and valid version number. Please note that if you do not providean AssemblyFileVersionAttributethen you'll get the right FileVersionInfoautomatically (with the same version of AssemblyVersionAttribute). You need to specify that attribute only if you need to set a different version.

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

回答by chamos

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

just remember to comment the AssemblyFileVersion line, otherwise the automatically generated assembly version will always be "1.0.0.0".

只记得注释AssemblyFileVersion 行,否则自动生成的程序集版本将始终为“1.0.0.0”。

回答by fred

In my opinion, using [assembly: AssemblyVersion("x.y.z.*")], Patchshouldn't be automatically numbered. Eg:

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

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

[程序集:AssemblyVersion("1.2.3.*")]

Using '*' in AssemblyVersionis good, but follow seemver.org we should use *for the revisionpart from version structure <major version>.<minor version>.<build number>.<revision>).

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

Given a version number MAJOR.MINOR.PATCH, increment the:

MAJOR version when you make incompatible API changes,

MINOR version when you add functionality in a backwards-compatible manner, and

PATCH version when you make backwards-compatible bug fixes.

给定版本号 MAJOR.MINOR.PATCH,增加:

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

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

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

回答by We B Martians

So why does the supplied comment say

那么为什么提供的评论说

// 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")]

but builds generate CS8357? Somebody didn't get the memo.

但构建生成 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. :)