Skip to content

Commit 2d7b9fd

Browse files
committed
Updated README.
1 parent 89d45fa commit 2d7b9fd

File tree

2 files changed

+78
-184
lines changed

2 files changed

+78
-184
lines changed

README.ja.md

+38-92
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,48 @@
1515

1616
## これは何?
1717

18-
Git タグ・ブランチベースの、全自動バージョン情報挿入パッケージです。
18+
.NETやそのドキュメントなどに、現在のバージョンを埋め込みたいと考えたことはありませんか?
19+
更に、CIでそのようさ操作を自動化したいが、追加の作業があまりに不透明かつ多くて閉口したことはありませんか?
1920

20-
* RelaxVersionerのNuGetパッケージをインストールするだけで、Gitのタグ・ブランチ・コミットメッセージだけを使って、バージョン管理が出来ます。つまり、追加のツール操作が不要なため、Gitさえ知っていれば学習コストがほとんどなく、CI環境にも容易に対応できます。
21-
* サポートしている言語と環境は、以下の通りです(恐らく、現在のほとんどの.NET開発環境に適合します):
22-
* C#・F#・VB.NET・C++/CLI、そしてNuGetパッケージング (dotnet cli packコマンド) とプレーンテキスト
23-
* 全てのターゲットフレームワーク (`net8.0`, `netcoreapp3.1`, `net48`, `net20` や他の全て).
24-
* Visual Studio 2022/2019/2017/2015, Rider, dotnet SDK cli, .NET 8/7/6/5, .NET Core 3.1/2.2 及び .NET Framework 4.6.1 以上の元で動作するMSBuild環境 (注: MSBuildの動作プラットフォームの事です、適用するターゲットフレームワークの事ではありません)、及びこれらを使用する任意のIDE。
25-
* ローカルのGitリポジトリから、自動的にタグ・ブランチの名称を取得し、アセンブリ属性に適用することが出来ます。
26-
* AssemblyInfo.csファイルを直接変更しません。RelaxVersionerはテンポラリファイルに定義を出力し、それをコンパイルさせます。
27-
* Visual Studio/MSBuildの中間出力フォルダーを自動的に使用するため、Gitリポジトリ内を汚すことがありません。
28-
* カスタムルールセットを定義することで、出力する属性と内容をカスタマイズすることが出来ます。
21+
C#ではこのような情報を、慣例で`AssemblyInfo.cs`ファイルに記述します:
2922

30-
### バージョン情報が埋め込まれた、Explorerで見るアセンブリのプロパティ
23+
```csharp
24+
using System.Reflection;
25+
26+
// アセンブリ属性でバージョン番号を埋め込む
27+
[assembly: AssemblyVersion("1.0.21")]
28+
```
29+
30+
しかし、標準で行われることはここまでです。埋め込まれたバージョン番号を適切に更新するのは、開発者の責任でした。
31+
32+
RelaxVersionerは、バージョンの適用をGitのタグ付けで行うことで、きわめてシンプルにバージョンの埋め込みを実現します。
33+
簡単に言えば、Gitタグに `1.0.21` と付ければ、自動的に上記のようなアセンブリ属性が生成されて埋め込まれると言う事です!
34+
35+
バージョン番号が埋め込まれたアセンブリは、Explorerのプロパティページでその一部を確認できます:
3136

3237
![Assembly property at the explorer](Images/Explorer.png)
3338

34-
### バージョン情報が埋め込まれた、ILSpyで見るアセンブリの属性群
39+
ILSpyで見れば、すべての情報も確認できるでしょう:
3540

3641
![Assembly wide attributes at ILSpy](Images/ILSpy.png)
3742

38-
----
43+
* RelaxVersionerのNuGetパッケージを、あなたの.NETプロジェクトにインストールするだけで、ビルド時にGitのタグからバージョン番号を完全に自動で埋め込みます。
44+
* タグが付いていないコミットでも心配ありません。過去にさかのぼってタグを見つけ、自動的にインクリメントされたバージョンを適用できます。
45+
* タグだけではありません。コミットID、ブランチ名、オーサー名や日付など、付随する情報も埋め込みます。フォーマットも自由に変更できます。
46+
* また、埋め込む対象の情報をカスタマイズする事もできます。例えば、MSBuildで使われる変数の値を埋め込むことで、ビルド時の詳細な情報も埋め込むことが出来ます。
47+
* バージョンの埋め込みは、完全にMSBuildに統合されます。つまり、NuGetパッケージをインストールするだけで、Visual Studio、Rider、Visual Studio CodeといったIDEや 、CIのビルドプロセスでそのままバージョン埋め込みを実現できます。
48+
* RelaxVersionerには、環境に依存するコードは含まれていないので、ほぼすべての.NET環境で動作します。
49+
* CLIインターフェイスも存在します。テキストドキュメントにバージョン番号を埋め込んだり、.NETとは異なるプロジェクトシステム(例えばNPMの`project.json``Makefile`など)に対しても、同じバージョン表記を適用できます。
50+
51+
### 出力されるコードの例
3952

40-
## 出力されるコードの例:
53+
以下はC#の例ですが、他にF#、VB.net、C++/CLIに対応しています。出力される属性は同じです。
4154

42-
### For C#:
55+
アセンブリ属性のほかに、 `ThisAssembly` シンボルも定義されます。これは、リフレクションを使って属性を探索しなくても、簡単に各種バージョン情報を取得できる利点があります:
4356

4457
``` csharp
4558
using System.Reflection;
59+
4660
[assembly: AssemblyVersion("1.0.21")]
4761
[assembly: AssemblyFileVersion("2020.12.20.33529")]
4862
[assembly: AssemblyInformationalVersion("1.0.21-561387e2f6dc90046f56ef4c3ac501aad0d5ec0a")]
@@ -95,78 +109,7 @@ namespace YourApp
95109
}
96110
```
97111

98-
### For F#:
99-
100-
``` fsharp
101-
namespace global
102-
open System.Reflection
103-
[<assembly: AssemblyVersion("1.0.21")>]
104-
[<assembly: AssemblyFileVersion("2020.12.20.33529")>]
105-
[<assembly: AssemblyInformationalVersion("1.0.21-561387e2f6dc90046f56ef4c3ac501aad0d5ec0a")>]
106-
[<assembly: AssemblyConfiguration("Release")>]
107-
[<assembly: AssemblyMetadata("AssemblyName","YourApp")>]
108-
[<assembly: AssemblyMetadata("TargetFrameworkMoniker","net6.0")>]
109-
[<assembly: AssemblyMetadata("Date","Sunday, April 23, 2023 9:42:21 PM 0900")>]
110-
[<assembly: AssemblyMetadata("Branch","master")>]
111-
[<assembly: AssemblyMetadata("Tags","")>]
112-
[<assembly: AssemblyMetadata("Author","Kouji Matsui <[email protected]>")>]
113-
[<assembly: AssemblyMetadata("Committer","Kouji Matsui <[email protected]>")>]
114-
[<assembly: AssemblyMetadata("Subject","Merge branch 'devel'")>]
115-
[<assembly: AssemblyMetadata("Body","")>]
116-
[<assembly: AssemblyMetadata("Build","")>]
117-
[<assembly: AssemblyMetadata("Generated","Sunday, April 23, 2023 9:42:21 PM 0900")>]
118-
[<assembly: AssemblyMetadata("Platform","AnyCPU")>]
119-
[<assembly: AssemblyMetadata("BuildOn","Unix")>]
120-
[<assembly: AssemblyMetadata("SdkVersion","7.0.100")>]
121-
[<assembly: AssemblyMetadata("ApplicationVersion","33529")>]
122-
[<assembly: AssemblyMetadata("ApplicationDisplayVersion","1.0.21")>]
123-
do()
124-
125-
namespace global
126-
module internal ThisAssembly =
127-
[<Literal>]
128-
let AssemblyVersion = "1.0.21"
129-
[<Literal>]
130-
let AssemblyFileVersion = "2020.12.20.33529"
131-
[<Literal>]
132-
let AssemblyInformationalVersion = "1.0.21-561387e2f6dc90046f56ef4c3ac501aad0d5ec0a"
133-
[<Literal>]
134-
let AssemblyConfiguration = "Release"
135-
module AssemblyMetadata =
136-
[<Literal>]
137-
let AssemblyName = "YourApp"
138-
[<Literal>]
139-
let TargetFrameworkMoniker = "net6.0"
140-
[<Literal>]
141-
let Date = "Sunday, April 23, 2023 9:42:21 PM 0900"
142-
[<Literal>]
143-
let Branch = "master"
144-
[<Literal>]
145-
let Tags = ""
146-
[<Literal>]
147-
let Author = "Kouji Matsui <[email protected]>"
148-
[<Literal>]
149-
let Committer = "Kouji Matsui <[email protected]>"
150-
[<Literal>]
151-
let Subject = "Merge branch 'devel'"
152-
[<Literal>]
153-
let Body = ""
154-
[<Literal>]
155-
let Build = ""
156-
[<Literal>]
157-
let Generated = "Sunday, April 23, 2023 9:42:21 PM 0900"
158-
[<Literal>]
159-
let Platform = "AnyCPU"
160-
[<Literal>]
161-
let BuildOn = "Unix"
162-
[<Literal>]
163-
let SdkVersion = "7.0.100"
164-
[<Literal>]
165-
let ApplicationVersion = "33529"
166-
[<Literal>]
167-
let ApplicationDisplayVersion = "1.0.21"
168-
do()
169-
```
112+
----
170113

171114
## RelaxVersionerの使い方
172115

@@ -207,7 +150,7 @@ namespace global
207150

208151
----
209152

210-
### コマンドラインインターフェイス (CLI)
153+
## コマンドラインインターフェイス (CLI)
211154

212155
RelaxVersionerは、dotnet CLI toolに対応しています。
213156
`rv`コマンドは、 `dotnet tool install -g rv-cli` でインストールすることが出来ます。
@@ -233,17 +176,20 @@ $ rv -f "{commitId}" .
233176
# 複雑なフォーマットも可能
234177
$ rv -f "{commitId}:{commitDate:yyyyMMdd}/{branches}" .
235178
0123456789 ...:20240123/develop,main
179+
```
180+
181+
* プレースホルダーに指定するシンボル `versionLabel`, `commitId` などは、後述の章を参照してください。
182+
* 注意: `tfm`, `tfid`, `tfv`, `tfp`, `namespace` 及び `buildIdentifier` は、それぞれコマンドラインオプションに指定されないと認識できません。
236183

184+
`-o`オプションを使用して、直接ファイルに出力できます。この場合は、終端に改行が含まれません:
185+
186+
```bash
237187
# ファイルに出力
238188
$ rv -o version.txt .
239189
$ cat version.txt
240190
1.2.3.4
241191
```
242192

243-
* プレースホルダーに指定するシンボル `versionLabel`, `commitId` などは、後述の章を参照してください。
244-
* 注意: `tfm`, `tfid`, `tfv`, `tfp`, `namespace` 及び `buildIdentifier` は、それぞれコマンドラインオプションに指定されないと認識できません。
245-
* `-o`を使用して出力した場合は、改行が含まれません。
246-
247193
`-r`または`-i`オプションを使用すると、任意のテキストを直接置き換える「リプレースモード」となります。
248194
このモードを使用すれば、もっと直接的にファイルを一括置換できます:
249195

README.md

+40-92
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,50 @@
1515

1616
## What is this?
1717

18-
Git tag/branch based, full-automatic version generator.
18+
Have you ever wanted to embed the current version of .NET, its documentation, etc.?
19+
Furthermore, have you ever wanted to automate such an operation with CI, but found the additional work to be too opaque and numerous?
1920

20-
* If you use RelaxVersioner, version handling only use with Git tags/branches/commit messages. Of course you only need to install NuGet package and don't need more tooling knowledge, and easy integrates continuous-integration environments.
21-
* Target language/environments (Probably fits most current .NET development environments):
22-
* C#, F#, VB.NET, C++/CLI, NuGet packaging (dotnet cli packer) and plain text forms.
23-
* All target frameworks (ALL: `net8.0`, `netcoreapp3.1`, `net48`, `net20` and others).
24-
* Visual Studio 2022/2019/2017/2015, Rider, dotnet SDK cli, MSBuild on .NET 8/7/6/5, .NET Core 3.1/2.2 and .NET Framework 4.6.1 environment (NOT your project target frameworks) and related IDEs.
25-
* Auto collect version information from local Git repository tags/branch name.
26-
* Independent AssemblyInfo.cs file, generated code will output into a temporary file. (Not manipulate directly AssemblyInfo.cs file).
27-
* Place source code location which isn't obstructive for Git. (ex: obj/Debug)
28-
* You can customize output attribute/values with custom rule set file.
21+
In C#, such information is conventionally described in the `AssemblyInfo.cs` file:
2922

30-
### Result for assembly property at the explorer
23+
```csharp
24+
using System.Reflection;.
3125

32-
![Result for assembly property at the explorer](Images/Explorer.png)
26+
// Embed version number in assembly attribute.
27+
[assembly: AssemblyVersion("1.0.21")]
28+
```
29+
30+
However, this is as far as the standard goes.
31+
It was the developer's responsibility to properly update the embedded version number.
32+
33+
RelaxVersioner makes version embedding extremely simple by applying versions via Git tagging.
34+
Simply put, you can tag a Git tag with `1.0.21` and it will automatically generate and embed an assembly attribute like the one shown above!
35+
36+
The assembly with the embedded version number can be partially viewed in the Properties page of Explorer:
3337

34-
### Result for assembly wide attributes at ILSpy
38+
![Assembly property at the explorer](Images/Explorer.png)
39+
40+
If you look in ILSpy, you will also see all the information:
3541

3642
![Assembly wide attributes at ILSpy](Images/ILSpy.png)
3743

38-
----
44+
* Simply install RelaxVersioner's NuGet package into your .NET project and it will embed the version number from your Git tags completely automatically at build time.
45+
* Don't worry about untagged commits. It can go back in time, find the tag, and apply the automatically incremented version.
46+
* This is not just a tag. It also embeds additional information such as commit ID, branch name, author name, date and etc. The format can be freely changed.
47+
* You can also customize the information to be embedded. For example, by embedding the value of variables used in MSBuild, you can also embed detailed information at build time.
48+
* Version embedding is fully integrated into MSBuild. This means that you can simply install the NuGet package and embed versions directly in the build process of IDEs such as Visual Studio, Rider, Visual Studio Code or in the build process of CI.
49+
* RelaxVersioner does not contain any environment-dependent code, so it works in almost any .NET environment.
50+
* A CLI interface also exists. You can embed version numbers in text documents and apply the same version notation to different project systems than .NET (e.g. NPM's `project.json`, `Makefile` and etc.).
3951

4052
## Sample output code
4153

42-
### For C#:
54+
The following is a C# example, but F#, VB.net, and C++/CLI are also supported. The output attributes are the same.
55+
56+
In addition to the assembly attributes, a `ThisAssembly` symbol is also defined.
57+
This has the advantage that you can easily retrieve various version information without having to use reflection to search for the attributes:
4358

4459
``` csharp
4560
using System.Reflection;
61+
4662
[assembly: AssemblyVersion("1.0.21")]
4763
[assembly: AssemblyFileVersion("2020.12.20.33529")]
4864
[assembly: AssemblyInformationalVersion("1.0.21-561387e2f6dc90046f56ef4c3ac501aad0d5ec0a")]
@@ -95,78 +111,7 @@ namespace YourApp
95111
}
96112
```
97113

98-
### For F#:
99-
100-
``` fsharp
101-
namespace global
102-
open System.Reflection
103-
[<assembly: AssemblyVersion("1.0.21")>]
104-
[<assembly: AssemblyFileVersion("2020.12.20.33529")>]
105-
[<assembly: AssemblyInformationalVersion("1.0.21-561387e2f6dc90046f56ef4c3ac501aad0d5ec0a")>]
106-
[<assembly: AssemblyConfiguration("Release")>]
107-
[<assembly: AssemblyMetadata("AssemblyName","YourApp")>]
108-
[<assembly: AssemblyMetadata("TargetFrameworkMoniker","net6.0")>]
109-
[<assembly: AssemblyMetadata("Date","Sunday, April 23, 2023 9:42:21 PM 0900")>]
110-
[<assembly: AssemblyMetadata("Branch","master")>]
111-
[<assembly: AssemblyMetadata("Tags","")>]
112-
[<assembly: AssemblyMetadata("Author","Kouji Matsui <[email protected]>")>]
113-
[<assembly: AssemblyMetadata("Committer","Kouji Matsui <[email protected]>")>]
114-
[<assembly: AssemblyMetadata("Subject","Merge branch 'devel'")>]
115-
[<assembly: AssemblyMetadata("Body","")>]
116-
[<assembly: AssemblyMetadata("Build","")>]
117-
[<assembly: AssemblyMetadata("Generated","Sunday, April 23, 2023 9:42:21 PM 0900")>]
118-
[<assembly: AssemblyMetadata("Platform","AnyCPU")>]
119-
[<assembly: AssemblyMetadata("BuildOn","Unix")>]
120-
[<assembly: AssemblyMetadata("SdkVersion","7.0.100")>]
121-
[<assembly: AssemblyMetadata("ApplicationVersion","33529")>]
122-
[<assembly: AssemblyMetadata("ApplicationDisplayVersion","1.0.21")>]
123-
do()
124-
125-
namespace global
126-
module internal ThisAssembly =
127-
[<Literal>]
128-
let AssemblyVersion = "1.0.21"
129-
[<Literal>]
130-
let AssemblyFileVersion = "2020.12.20.33529"
131-
[<Literal>]
132-
let AssemblyInformationalVersion = "1.0.21-561387e2f6dc90046f56ef4c3ac501aad0d5ec0a"
133-
[<Literal>]
134-
let AssemblyConfiguration = "Release"
135-
module AssemblyMetadata =
136-
[<Literal>]
137-
let AssemblyName = "YourApp"
138-
[<Literal>]
139-
let TargetFrameworkMoniker = "net6.0"
140-
[<Literal>]
141-
let Date = "Sunday, April 23, 2023 9:42:21 PM 0900"
142-
[<Literal>]
143-
let Branch = "master"
144-
[<Literal>]
145-
let Tags = ""
146-
[<Literal>]
147-
let Author = "Kouji Matsui <[email protected]>"
148-
[<Literal>]
149-
let Committer = "Kouji Matsui <[email protected]>"
150-
[<Literal>]
151-
let Subject = "Merge branch 'devel'"
152-
[<Literal>]
153-
let Body = ""
154-
[<Literal>]
155-
let Build = ""
156-
[<Literal>]
157-
let Generated = "Sunday, April 23, 2023 9:42:21 PM 0900"
158-
[<Literal>]
159-
let Platform = "AnyCPU"
160-
[<Literal>]
161-
let BuildOn = "Unix"
162-
[<Literal>]
163-
let SdkVersion = "7.0.100"
164-
[<Literal>]
165-
let ApplicationVersion = "33529"
166-
[<Literal>]
167-
let ApplicationDisplayVersion = "1.0.21"
168-
do()
169-
```
114+
----
170115

171116
## Getting started
172117

@@ -228,17 +173,21 @@ $ rv -f "{commitId}" .
228173
# Complex formats are also possible
229174
$ rv -f "{commitId}:{commitDate:yyyyMMdd}/{branches}" .
230175
0123456789 ...:20240123/develop,main
176+
```
177+
178+
* Please refer to below section such as `versionLabel`, `commitId` and etc. that are specified as placeholders.
179+
* Note: `tfm`, `tfid`, `tfv`, `tfp`, `namespace` and `buildIdentifier` cannot be recognized unless they are specified as command line options.
231180

181+
You can use the `-o` option to output directly to a file.
182+
In this case, no newlines are included at the end of the line:
183+
184+
```bash
232185
# Output to the file
233186
$ rv -o version.txt .
234187
$ cat version.txt
235188
1.2.3.4
236189
```
237190

238-
* Please refer to below section such as `versionLabel`, `commitId` and etc. that are specified as placeholders.
239-
* Note: `tfm`, `tfid`, `tfv`, `tfp`, `namespace` and `buildIdentifier` cannot be recognized unless they are specified as command line options.
240-
* If you use `-o` to output, it will not include line breaks.
241-
242191
If you use the `-r` or `-i` options, you will be in “replace mode”, which allows you to directly replace arbitrary text.
243192
Using this mode, you can perform bulk text replacements in a more direct way:
244193

@@ -261,7 +210,6 @@ $ echo "ABC#{commitId}#XYZ" | rv -r --bracket "#{,}#" .
261210
ABC0123456789abc ... XYZ
262211
```
263212

264-
Translated with DeepL.com (free version)
265213
With this CLI, you can use a combination of RelaxVersioner for different targets than .NET.
266214
For example, in a CI/CD environment like GitHub Actions, you can apply versions to NPM package generation or embed versions in your text documentation.
267215

0 commit comments

Comments
 (0)