dotnet / Nerdbank.GitVersioning

Stamp your assemblies, packages and more with a unique version generated from a single, simple version.json file and include git commit IDs for non-official builds.
https://www.nuget.org/packages/Nerdbank.GitVersioning
MIT License
1.32k stars 165 forks source link

override NGBV produced version #1053

Open KunalSaini opened 1 month ago

KunalSaini commented 1 month ago

Hi, I am trying to set NuGet package version of in a csproj file like below.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Version>2.2.2</Version>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" PrivateAssets="all" />
  </ItemGroup>
</Project>

This project is not in a git repository. The project does not have a version.json file. I would have expected it to produce v2.2.2 of NuGet package on dotnet build , however it produces v0.0.0-g

I tried passing in version explicitly dotnet build /p:Version=2.2.2 , still it produces the v0.0.0-g package version.

I am using dotnet sdk 8.0.102 for build, if that matters.

Question: how do i override this NBGV behavior.

AArnott commented 1 month ago

Question: Why are you installing the Nerdbank.GitVersioning package if you're not in a git repo and don't want it to set the version?

KunalSaini commented 1 month ago

This is just an example I put together to understand the versioning override mechanism, in reality, we have a lot of separate .net repositories in git and we maintain a custom sdk that brings/enforces common packages/functionality to all repositories/solutions. We are considering putting NBGV in our custom sdk so that its available to all repositories. And each repository owner can switch to NBGV on their own pace (by introducing proper version.json that makes sense for their repository) My initial understanding was that if version.json is absent in a repository , the old/existing versioning mechanism will continue to work, for example lot of repositories use msbuild switch to specify version in our CI/CD environment. However, when i tries that, it failed to set the version number if the repo is using NBGV.

AArnott commented 1 month ago

I see. No, the behavior you're seeing is the intended behavior. That is, elements of it activate even without git and without a version.json file. You can check out our msbuild docs for how to customize the output, but having the package installed without an intention to use it hasn't been a scenario so far.