You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Installing the Nerdbank.GitVersioning package from NuGet into your
4
-
MSBuild-based projects
3
+
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.
5
4
6
5
## Public releases
7
6
@@ -12,11 +11,56 @@ in order to avoid the git commit ID being included in the NuGet package version.
12
11
13
12
From the command line, building a release version might look like this:
14
13
15
-
msbuild /p:PublicRelease=true
14
+
```ps1
15
+
msbuild /p:PublicRelease=true
16
+
```
16
17
17
18
Note you may consider passing this switch to any build that occurs in the
18
-
branch that you publish released NuGet packages from.
19
+
branch that you publish released NuGet packages from.
19
20
You should only build with this property set from one release branch per
20
21
major.minor version to avoid the risk of producing multiple unique NuGet
21
22
packages with a colliding version spec.
22
23
24
+
## Build performance
25
+
26
+
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.
27
+
You can assess the impact that Nerdbank.GitVersioning has on your build time by running a build with the `-clp:PerformanceSummary` switch and look for the `Nerdbank.GitVersioning.Tasks.GetBuildVersion` task.
28
+
29
+
### Reducing `GetBuildVersion` invocations
30
+
31
+
If the `GetBuildVersion` task is running many times, yet you have just one (or a few) `version.json` files in your repository, you can reduce this task to being called just once per `version.json` file to *significantly* improve build performance.
32
+
To do this, drop a `Directory.Build.props` file in the same directory as your `version.json` file(s) with this content:
This MSBuild property instructs all projects in or under that directory to share a computed version based on that directory rather than their individual project directories.
43
+
Check the impact of this change by re-running MSBuild with the `-clp:PerformanceSummary` switch as described above.
44
+
45
+
If you still see many invocations, you may have a build that sets global properties on P2P references.
46
+
Investigate this using the MSBuild `/bl` switch and view the log with the excellent [MSBuild Structured Log Viewer](https://msbuildlog.com) tool.
47
+
Using that tool, search for `$task GetBuildVersion` and look at the global properties passed to the special `Nerdbank.GitVersioning.Inner.targets` project, as shown:
<WarningCondition=" '$(AssemblyInformationalVersion)' == '' "Text="Unable to determine the git HEAD commit ID to use for informational version number." />
39
+
<MessageCondition=" '$(AssemblyInformationalVersion)' != '' "Text="Building version $(BuildVersion) from commit $(GitCommitId)"/>
40
+
<MessageCondition=" '$(AssemblyInformationalVersion)' == '' "Text="Building version $(BuildVersion)"/>
0 commit comments