Skip to content

Commit 192d62e

Browse files
committed
Improve msbuild documentation
1 parent dae20a6 commit 192d62e

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

doc/msbuild.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
Installing the `Nerdbank.GitVersioning` package from NuGet into your MSBuild-based projects is the recommended way to add version information to your MSBuild project outputs including assemblies, native dll's, and packages.
44

5+
If you want the package to affect all the projects in your repo, and you use `PackageReference` (rather than `packages.config`),
6+
you can add this to a repo-level `Directory.Build.props` file:
7+
8+
```xml
9+
<ItemGroup>
10+
<PackageReference Include="Nerdbank.GitVersioning"
11+
Version="(latest-version-here)"
12+
PrivateAssets="all"
13+
Condition="!Exists('packages.config')" />
14+
</ItemGroup>
15+
```
16+
17+
The condition prevents the `PackageReference` from impacting any `packages.config`-based projects
18+
such as vcxproj that may be in your repo.
19+
Such projects will require individual installation of the Nerdbank.GitVersioning nuget package
20+
using the NuGet Package Manager in Visual Studio.
21+
522
## Public releases
623

724
By default, each build of a Nuget package will include the git commit ID.
@@ -21,6 +38,64 @@ You should only build with this property set from one release branch per
2138
major.minor version to avoid the risk of producing multiple unique NuGet
2239
packages with a colliding version spec.
2340

41+
## Custom build authoring
42+
43+
If you are writing your own MSBuild targets or properties and need to consume version information,
44+
Nerdbank.GitVersioning is there to help.
45+
The version information created by this package is expressed as MSBuild properties.
46+
These properties are set by the `GetBuildVersion` target defined in this package.
47+
This means any dependency you have on these properties must ensure this target has already executed.
48+
This can be done by defining your own msbuild target like so:
49+
50+
```xml
51+
<Target Name="MyPropertySetter" DependsOnTargets="GetBuildVersion">
52+
<PropertyGroup>
53+
<MyOwnProperty>My assembly version is: $(AssemblyVersion)</MyOwnProperty>
54+
</PropertyGroup>
55+
</Target>
56+
```
57+
58+
In the above example, the `AssemblyVersion` property, which is set by the
59+
`GetBuildVersion` target defined by Nerdbank.GitVersioning, is used to define
60+
another property.
61+
It could also be used to define msbuild items or anything else you want.
62+
63+
### MSBuild properties defined in `GetBuildVersion`
64+
65+
Many MSBuild properties are set by `GetBuildVersion` allowing you to define or redefine
66+
properties in virtually any format you like.
67+
The authoritative list is [here](https://github.com/dotnet/Nerdbank.GitVersioning/blob/dae20a6d15f04d8161fd092c36fdf1f57c021ba1/src/Nerdbank.GitVersioning.Tasks/GetBuildVersion.cs#L300-L323) (switch to the default branch to see the current set).
68+
69+
Below is a snapshot of the properties with example values.
70+
Note that the values and formats can vary depending on your `version.json` settings and version height.
71+
72+
Property | Example value
73+
--|--
74+
AssemblyFileVersion | 2.7.74.11627
75+
AssemblyInformationalVersion | 2.7.74-alpha+6b2d14ba68
76+
AssemblyVersion | 2.7.0.0
77+
BuildingRef | refs/heads/fix299
78+
BuildNumber | 74
79+
BuildVersion | 2.7.74.11627
80+
BuildVersion3Components | 2.7.74
81+
BuildVersionNumberComponent | 74
82+
BuildVersionSimple | 2.7.74
83+
ChocolateyPackageVersion | 2.7.74-alpha-g6b2d14ba68
84+
CloudBuildNumber | (empty except in cloud build)
85+
FileVersion | 2.7.74.11627
86+
GitCommitDateTicks | 637547960670000000
87+
GitCommitId | 6b2d14ba6844d2152c48268a8d2c1933759e7229
88+
GitCommitIdShort | 6b2d14ba68
89+
GitVersionHeight | 74
90+
MajorMinorVersion | 2.7
91+
NPMPackageVersion | 2.7.74-alpha.g6b2d14ba68
92+
NuGetPackageVersion | 2.7.74-alpha-g6b2d14ba68
93+
PackageVersion | 2.7.74-alpha-g6b2d14ba68
94+
PrereleaseVersion | -alpha
95+
PublicRelease | False
96+
SemVerBuildSuffix | +6b2d14ba68
97+
Version | 2.7.74-alpha-g6b2d14ba68
98+
2499
## Build performance
25100

26101
Repos with many projects or many commits between major/minor version bumps can suffer from compromised build performance due to the MSBuild task that computes the version information for each project.

0 commit comments

Comments
 (0)