Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOWTO dotnet core nuget versioning #45

Closed
Boggin opened this issue Jul 3, 2017 · 4 comments
Closed

HOWTO dotnet core nuget versioning #45

Boggin opened this issue Jul 3, 2017 · 4 comments

Comments

@Boggin
Copy link

Boggin commented Jul 3, 2017

GitInfo is correctly versioning our assemblies but I would like to extend this to versioning our nuget packages. The following is a snippet from our .csproj :

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    <PackageVersion>$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)$(GitSemVerDashLabel)</PackageVersion>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="..\..\GlobalAssemblyInfo.cs" Link="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="gitinfo" Version="1.1.66" />
  </ItemGroup>
</Project>

Note the GeneratePackageOnBuild.

What do I have to do to generate those environment variables, $(GitSemVerMajor), etc. when I call dotnet build?

@kzu
Copy link
Member

kzu commented Jul 4, 2017

Those are not environment variables, they are MSBuild variables determined during the build. Here's one way to do it.

The PackageVersion property has to be set from within a target that depends on GitVersion, which is when everything has been populated. You can achieve that by adding it as an InitialTargets:

<Project Sdk="Microsoft.NET.Sdk" InitialTargets="SetVersion">
...

@kzu kzu closed this as completed Jul 4, 2017
@feliwir
Copy link

feliwir commented Jun 3, 2018

The link is dead. Can you please provide a fresh minimal example?

@Boggin
Copy link
Author

Boggin commented Jun 3, 2018

The link refers to the Version.targets in the moq project build: https://github.com/moq/moq/blob/master/src/build/Version.targets

@kzu
Copy link
Member

kzu commented Jun 14, 2018

@feliwir the key is that you cannot assign those properties statically in a PropertyGroup, but must do so inside a Target that runs after GitInfo target runs

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants