Skip to content

Inject into correct point in build pipeline for VS 2017 #1119

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

Merged
merged 5 commits into from
Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion docs/usage/msbuild-task.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ The MSBuild Task for GitVersion — **GitVersionTask** — is a simple solution
you want to version your assemblies without writing any command line scripts or
modifying your build process.

It currently works with desktop `MSBuild`. Support for CoreCLR with `dotnet build` is coming soon.

## TL;DR

### Install the MSTask targets
Expand All @@ -16,6 +18,14 @@ From the Package Manager Console:
Install-Package GitVersionTask
```

If you're using `PackageReference` style NuGet dependencies (VS 2017+), add `<PrivateAssets>all</PrivateAssets>` to prevent the task from becoming a dependency of your package:

``` xml
<PackageReference Include="GitVersionTask" Version="4.0.0-beta*">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
```

### Remove AssemblyInfo attributes

The next thing you need to do is to remove the `Assembly*Version` attributes from
Expand Down Expand Up @@ -115,6 +125,17 @@ However at MSBuild time these properties are mapped to MSBuild properties that
are prefixed with `GitVersion_`. This prevents conflicts with other properties
in the pipeline.

In addition, the following MSBuild properties are set when `UpdateVersionProperties` is true (the default):
`Version`, `VersionPrefix`, `VersionSuffix`, `PackageVersion`, `InformationalVersion`, `AssemblyVersion` and `FileVersion`. These are used by the built-in tasks for generating AssemblyInfo's and NuGet package versions.


### NuGet packages
The new SDK-style projects available for .NET Standard libraries (and multi-targeting), have the ability
to create NuGet packages directly by using the `pack` target: `msbuild /t:pack`. The version is controled by the MSBuild properties described above.

GitVersionTask has the option to generate SemVer 2.0 compliant NuGet package versions by setting `UseFullSemVerForNuGet` to true in your project (this is off by default for compatibility). Some hosts, like MyGet, support SemVer 2.0 package versions but older NuGet clients and nuget.org do not.


#### Accessing variables in MSBuild

Once `GitVersionTask.GetVersion` has been executed, the MSBuild properties can be
Expand All @@ -136,7 +157,7 @@ Build Server log in a format that the current Build Server can consume. See

## Conditional control tasks

Properties `WriteVersionInfoToBuildLog`, `UpdateAssemblyInfo` and `GetVersion`
Properties `WriteVersionInfoToBuildLog`, `UpdateAssemblyInfo`, `UseFullSemVerForNuGet`, `UpdateVersionProperties` and `GetVersion`
are checked before running these tasks.

You can disable `GitVersionTask.UpdateAssemblyInfo` by setting
Expand All @@ -150,6 +171,7 @@ this:
...
</PropertyGroup>
```
For SDK-style projects, `UpdateVersionProperties` controls setting the default variables: `Version`, `VersionPrefix`, `VersionSuffix`, `PackageVersion`, `InformationalVersion`, `AssemblyVersion` and `FileVersion`.

## My Git repository requires authentication. What should I do?

Expand Down
8 changes: 4 additions & 4 deletions src/GitVersionTask/GitVersionTask.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="NugetAssets\GitVersionTask.targets">
<SubType>Designer</SubType>
</None>
<None Include="NugetAssets\buildMultiTargeting\GitVersionTask.targets" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the file NugetAssets\GitVersionTask.targets be deleted?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was moved into the build folder

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, missed this :)

<None Include="NugetAssets\build\GitVersionTask.targets" />
<None Include="NugetAssets\GitVersionTask.nuspec">
<SubType>Designer</SubType>
</None>
Expand Down Expand Up @@ -127,7 +126,8 @@
<Copy SourceFiles="$(TargetDir)ILMergeTemp\GitVersionTask.dll" DestinationFolder="$(BuildDir)NuGetTaskBuild\build" Condition="Exists('$(TargetDir)ILMergeTemp\GitVersionTask.dll')" />
<Copy SourceFiles="$(TargetDir)GitVersionTask.pdb" DestinationFolder="$(BuildDir)NuGetTaskBuild\build" Condition="Exists('$(TargetDir)GitVersionTask.pdb')" />
<Copy SourceFiles="$(TargetDir)GitVersionTask.dll.mdb" DestinationFolder="$(BuildDir)NuGetTaskBuild\build" Condition="Exists('$(TargetDir)GitVersionTask.dll.mdb')" />
<Copy SourceFiles="$(ProjectDir)NugetAssets\GitVersionTask.targets" DestinationFolder="$(BuildDir)NuGetTaskBuild\build" />
<Copy SourceFiles="$(ProjectDir)NugetAssets\build\GitVersionTask.targets" DestinationFolder="$(BuildDir)NuGetTaskBuild\build" />
<Copy SourceFiles="$(ProjectDir)NugetAssets\buildMultiTargeting\GitVersionTask.targets" DestinationFolder="$(BuildDir)NuGetTaskBuild\buildMultiTargeting" />
<Copy SourceFiles="$(ProjectDir)NugetAssets\GitVersionTask.nuspec" DestinationFolder="$(BuildDir)NuGetTaskBuild" />
<PepitaPackage.CreatePackageTask NuGetBuildDirectory="$(BuildDir)NuGetTaskBuild" MetadataAssembly="$(ILMergeTemp)GitVersionTask.dll" Version="$(GitVersion_NuGetVersion)" />
<Delete Files="@(TempFiles)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
<!-- Property that enables WriteVersionInfoToBuildLog -->
<WriteVersionInfoToBuildLog Condition=" '$(WriteVersionInfoToBuildLog)' == '' ">true</WriteVersionInfoToBuildLog>

<!-- Property that enables UpdateAssemblyInfo -->
<!-- Property that enables UpdateAssemblyInfo. Default to off for SDK builds -->
<UpdateAssemblyInfo Condition=" '$(UpdateAssemblyInfo)' == '' and '$(TargetFramework)' != '' ">false</UpdateAssemblyInfo>
<UpdateAssemblyInfo Condition=" '$(UpdateAssemblyInfo)' == '' ">true</UpdateAssemblyInfo>

<!-- Property that enables setting of Version -->
<UpdateVersionProperties Condition=" '$(UpdateVersionProperties)' == '' ">true</UpdateVersionProperties>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if these properties can be documented here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will update the docs now

<UseFullSemVerForNuGet Condition=" '$(UseFullSemVerForNuGet)' == '' ">false</UseFullSemVerForNuGet>

<!-- Property that enables GetVersion -->
<GetVersion Condition=" '$(GetVersion)' == '' ">true</GetVersion>
Expand All @@ -27,7 +32,7 @@
TaskName="GitVersionTask.WriteVersionInfoToBuildLog"
AssemblyFile="$(GitVersionTaskLibrary)GitVersionTask.dll" />

<Target Name="WriteVersionInfoToBuildLog" BeforeTargets="CoreCompile" Condition="$(WriteVersionInfoToBuildLog) == 'true'">
<Target Name="WriteVersionInfoToBuildLog" BeforeTargets="CoreCompile;GetAssemblyVersion;GenerateNuspec" Condition="$(WriteVersionInfoToBuildLog) == 'true'">
<WriteVersionInfoToBuildLog SolutionDirectory="$(SolutionDir)" NoFetch="$(GitVersion_NoFetchEnabled)"/>
</Target>

Expand All @@ -49,7 +54,7 @@
</ItemGroup>
</Target>

<Target Name="GetVersion" BeforeTargets="CoreCompile" Condition="$(GetVersion) == 'true'">
<Target Name="GetVersion" BeforeTargets="CoreCompile;GetAssemblyVersion;GenerateNuspec" Condition="$(GetVersion) == 'true'">

<GetVersion SolutionDirectory="$(SolutionDir)" NoFetch="$(GitVersion_NoFetchEnabled)">
<Output TaskParameter="Major" PropertyName="GitVersion_Major" />
Expand Down Expand Up @@ -77,6 +82,18 @@
<Output TaskParameter="CommitsSinceVersionSource" PropertyName="GitVersion_CommitsSinceVersionSource" />
<Output TaskParameter="CommitsSinceVersionSourcePadded" PropertyName="GitVersion_CommitsSinceVersionSourcePadded" />
</GetVersion>

<PropertyGroup Condition=" '$(UpdateVersionProperties)' == 'true' ">
<Version>$(GitVersion_FullSemVer)</Version>
<VersionPrefix>$(GitVersion_MajorMinorPatch)</VersionPrefix>
<VersionSuffix Condition=" '$(UseFullSemVerForNuGet)' == 'false' ">$(GitVersion_NuGetPreReleaseTag)</VersionSuffix>
<VersionSuffix Condition=" '$(UseFullSemVerForNuGet)' == 'true' ">$(GitVersion_PreReleaseTag)</VersionSuffix>
<PackageVersion Condition=" '$(UseFullSemVerForNuGet)' == 'false' ">$(GitVersion_NuGetVersion)</PackageVersion>
<PackageVersion Condition=" '$(UseFullSemVerForNuGet)' == 'true' ">$(GitVersion_FullSemVer)</PackageVersion>
<InformationalVersion Condition=" '$(InformationalVersion)' == '' ">$(GitVersion_InformationalVersion)</InformationalVersion>
<AssemblyVersion Condition=" '$(AssemblyVersion)' == '' ">$(GitVersion_AssemblySemVer)</AssemblyVersion>
<FileVersion Condition=" '$(FileVersion)' == '' ">$(GitVersion_MajorMinorPatch).$(GitVersion_CommitsSinceVersionSource)</FileVersion>
</PropertyGroup>

</Target>

Expand All @@ -93,6 +110,4 @@
</None>
</ItemGroup>

</Project>


</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<GitVersion_NoFetchEnabled Condition="$(GitVersion_NoFetchEnabled) == ''">false</GitVersion_NoFetchEnabled>

<!-- Property that enables WriteVersionInfoToBuildLog -->
<WriteVersionInfoToBuildLog Condition=" '$(WriteVersionInfoToBuildLog)' == '' ">true</WriteVersionInfoToBuildLog>

<!-- Property that enables UpdateAssemblyInfo. Default to off for SDK builds -->
<UpdateAssemblyInfo Condition=" '$(UpdateAssemblyInfo)' == '' and '$(TargetFramework)' != '' ">false</UpdateAssemblyInfo>
<UpdateAssemblyInfo Condition=" '$(UpdateAssemblyInfo)' == '' ">true</UpdateAssemblyInfo>

<GetVersion Condition=" '$(GetVersion)' == '' ">true</GetVersion>

<!-- Property that enables setting of Version -->
<UpdateVersionProperties Condition=" '$(UpdateVersionProperties)' == '' ">true</UpdateVersionProperties>
<UseFullSemVerForNuGet Condition=" '$(UseFullSemVerForNuGet)' == '' ">false</UseFullSemVerForNuGet>

<GitVersionTaskLibrary>$(MSBuildThisFileDirectory)..\build\</GitVersionTaskLibrary>
</PropertyGroup>

<UsingTask
TaskName="GitVersionTask.UpdateAssemblyInfo"
AssemblyFile="$(GitVersionTaskLibrary)GitVersionTask.dll" />
<UsingTask
TaskName="GitVersionTask.GetVersion"
AssemblyFile="$(GitVersionTaskLibrary)GitVersionTask.dll" />
<UsingTask
TaskName="GitVersionTask.WriteVersionInfoToBuildLog"
AssemblyFile="$(GitVersionTaskLibrary)GitVersionTask.dll" />

<Target Name="WriteVersionInfoToBuildLog" BeforeTargets="DispatchToInnerBuilds;GenerateNuspec" Condition="$(WriteVersionInfoToBuildLog) == 'true'">
<WriteVersionInfoToBuildLog SolutionDirectory="$(SolutionDir)" NoFetch="$(GitVersion_NoFetchEnabled)"/>
</Target>

<Target Name="GetVersion" BeforeTargets="DispatchToInnerBuilds;GenerateNuspec" Condition="$(GetVersion) == 'true'">

<GetVersion SolutionDirectory="$(SolutionDir)" NoFetch="$(GitVersion_NoFetchEnabled)">
<Output TaskParameter="Major" PropertyName="GitVersion_Major" />
<Output TaskParameter="Minor" PropertyName="GitVersion_Minor" />
<Output TaskParameter="Patch" PropertyName="GitVersion_Patch" />
<Output TaskParameter="BuildMetaData" PropertyName="GitVersion_BuildMetaData" />
<Output TaskParameter="BuildMetaDataPadded" PropertyName="GitVersion_BuildMetaDataPadded" />
<Output TaskParameter="FullBuildMetaData" PropertyName="GitVersion_FullBuildMetaData" />
<Output TaskParameter="BranchName" PropertyName="GitVersion_BranchName" />
<Output TaskParameter="Sha" PropertyName="GitVersion_Sha" />
<Output TaskParameter="MajorMinorPatch" PropertyName="GitVersion_MajorMinorPatch" />
<Output TaskParameter="SemVer" PropertyName="GitVersion_SemVer" />
<Output TaskParameter="LegacySemVer" PropertyName="GitVersion_LegacySemVer" />
<Output TaskParameter="LegacySemVerPadded" PropertyName="GitVersion_LegacySemVerPadded" />
<Output TaskParameter="FullSemVer" PropertyName="GitVersion_FullSemVer" />
<Output TaskParameter="AssemblySemVer" PropertyName="GitVersion_AssemblySemVer" />
<Output TaskParameter="NuGetVersion" PropertyName="GitVersion_NuGetVersion" />
<Output TaskParameter="NuGetPreReleaseTag" PropertyName="GitVersion_NuGetPreReleaseTag" />
<Output TaskParameter="PreReleaseTag" PropertyName="GitVersion_PreReleaseTag" />
<Output TaskParameter="PreReleaseTagWithDash" PropertyName="GitVersion_PreReleaseTagWithDash" />
<Output TaskParameter="PreReleaseLabel" PropertyName="GitVersion_PreReleaseLabel" />
<Output TaskParameter="PreReleaseNumber" PropertyName="GitVersion_PreReleaseNumber" />
<Output TaskParameter="InformationalVersion" PropertyName="GitVersion_InformationalVersion" />
<Output TaskParameter="CommitDate" PropertyName="GitVersion_CommitDate" />
<Output TaskParameter="CommitsSinceVersionSource" PropertyName="GitVersion_CommitsSinceVersionSource" />
<Output TaskParameter="CommitsSinceVersionSourcePadded" PropertyName="GitVersion_CommitsSinceVersionSourcePadded" />
</GetVersion>

<PropertyGroup Condition=" '$(UpdateVersionProperties)' == 'true' ">
<Version>$(GitVersion_FullSemVer)</Version>
<VersionPrefix>$(GitVersion_MajorMinorPatch)</VersionPrefix>
<VersionSuffix Condition=" '$(UseFullSemVerForNuGet)' == 'false' ">$(GitVersion_NuGetPreReleaseTag)</VersionSuffix>
<VersionSuffix Condition=" '$(UseFullSemVerForNuGet)' == 'true' ">$(GitVersion_PreReleaseTag)</VersionSuffix>
<PackageVersion Condition=" '$(UseFullSemVerForNuGet)' == 'false' ">$(GitVersion_NuGetVersion)</PackageVersion>
<PackageVersion Condition=" '$(UseFullSemVerForNuGet)' == 'true' ">$(GitVersion_FullSemVer)</PackageVersion>
<InformationalVersion Condition=" '$(InformationalVersion)' == '' ">$(GitVersion_InformationalVersion)</InformationalVersion>
<AssemblyVersion Condition=" '$(AssemblyVersion)' == '' ">$(GitVersion_AssemblySemVer)</AssemblyVersion>
<FileVersion Condition=" '$(FileVersion)' == '' ">$(GitVersion_MajorMinorPatch).$(GitVersion_CommitsSinceVersionSource)</FileVersion>
</PropertyGroup>

</Target>
</Project>