Skip to content

Add C++ (Modern/UWP,MFC, etc.) support for SemVer in GitVersion #1428

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
8 changes: 7 additions & 1 deletion src/GitVersionCore/GitVersionCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
<HintPath>..\packages\LibGit2Sharp.0.23.0-pre20160922233542\lib\net40\LibGit2Sharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll</HintPath>

Choose a reason for hiding this comment

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

I think you don't need to reference assembly by explicit path.

Copy link
Author

Choose a reason for hiding this comment

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

Bah! I blame visual studio for this abomination! Thanks. I will just revert this to the original line.

</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand Down Expand Up @@ -202,6 +204,10 @@
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="GitVersionInformationResources\AddFormats\GitVersionInformation.h" />
<EmbeddedResource Include="GitVersionInformationResources\Templates\GitVersionInformation.h" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define {0} {1}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// GitVersion
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

#pragma once

//------------------------------------------------------------------------------
//What the values SHOULD look like after the template is applied:
//#define VERSION_FULL MAJORVERSION,MINORVERSION,BUILDVERSION,REVISIONVERSION
//#define VERSION_STRING VERSION_XSTR(MAJORVERSION.MINORVERSION.BUILDVERSION.REVISIONVERSION-REVISIONHASH) VERSION_BLANK "\0"

//NOTE: The trailing "\0" is VERY important

//------------------------------------------------------------------------------

#define VERSION_STR(x) #x
#define VERSION_XSTR(x) VERSION_STR(x)
#define VERSION_BLANK ""

#define VERSION_FULL 0,0,0,1
#define VERSION_STRING VERSION_XSTR(0.0.0.1) VERSION_BLANK "\0"
9 changes: 5 additions & 4 deletions src/GitVersionCore/TemplateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
using System.Linq;
using GitVersionCore.Extensions;

enum TemplateType
public enum TemplateType
{
VersionAssemblyInfoResources,
GitVersionInformationResources
GitVersionInformationResources,
NativeHeader,
}

class TemplateManager
public class TemplateManager
{
readonly Dictionary<string, string> templates;
readonly Dictionary<string, string> addFormats;
Expand Down Expand Up @@ -80,4 +81,4 @@ static IEnumerable<string> GetEmbeddedTemplates(TemplateType templateType, strin
}
}
}
}
}
15 changes: 9 additions & 6 deletions src/GitVersionTask/GenerateGitVersionInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ string GetFileExtension()
{
switch (Language)
{
case "C#":
return "cs";
case SupportedLanguageConstants.CSHARP:
return SupportedLanguageConstants.FILEEXTENSION_CSHARP;

case "F#":
return "fs";
case SupportedLanguageConstants.FSHARP:
return SupportedLanguageConstants.FILEEXTENSION_FSHARP;

case "VB":
return "vb";
case SupportedLanguageConstants.VBDOTNET:
return SupportedLanguageConstants.FILEEXTENSION_VBDOTNET;

case SupportedLanguageConstants.CPLUSPLUS:
return SupportedLanguageConstants.FILEEXTENSION_CPLUSPLUS;

default:
throw new Exception($"Unknown language detected: '{Language}'");
Expand Down
2 changes: 2 additions & 0 deletions src/GitVersionTask/GitVersionTask.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
<Compile Include="BuildLogger.cs" />
<Compile Include="GenerateGitVersionInformation.cs" />
<Compile Include="GitVersionTaskBase.cs" />
<Compile Include="SupportedLanguageConstants.cs" />
<Compile Include="UpdateNativeVersionHeader.cs" />
<Compile Include="WriteVersionInfoToBuildLog.cs" />
<Compile Include="GetVersion.cs" />
<Compile Include="InvalidFileChecker.cs" />
Expand Down
31 changes: 29 additions & 2 deletions src/GitVersionTask/NugetAssets/build/GitVersionTask.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<PropertyGroup>
<GitVersion_Task_targets_Imported>True</GitVersion_Task_targets_Imported>
</PropertyGroup>
<PropertyGroup Condition=" '$(MSBuildProjectExtension)' == '.vcxproj' ">
<UpdateAssemblyInfo Condition=" '$(UpdateAssemblyInfo)' == '' ">false</UpdateAssemblyInfo>
<UpdateNativeHeader Condition=" '$(UpdateNativeHeader)' == '' ">true</UpdateNativeHeader>
</PropertyGroup>
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<GitVersionPath Condition="'$(GitVersionPath)' == '' And '$(GitVersionUseSolutionDir)' == 'true'">$(SolutionDir)</GitVersionPath>
Expand All @@ -22,6 +26,8 @@
<UpdateAssemblyInfo Condition=" '$(UpdateAssemblyInfo)' == '' and '$(NCrunch)' != '' ">false</UpdateAssemblyInfo>
<UpdateAssemblyInfo Condition=" '$(UpdateAssemblyInfo)' == '' ">true</UpdateAssemblyInfo>

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

<!-- Property that enables GenerateGitVersionInformation -->
<GenerateGitVersionInformation Condition=" '$(GenerateGitVersionInformation)' == '' and '$(NCrunch)' != '' ">false</GenerateGitVersionInformation>
<GenerateGitVersionInformation Condition=" '$(GenerateGitVersionInformation)' == '' ">true</GenerateGitVersionInformation>
Expand All @@ -42,6 +48,9 @@
<UsingTask
TaskName="GitVersionTask.UpdateAssemblyInfo"
AssemblyFile="$(GitVersionTaskLibrary)GitVersionTask.dll" />
<UsingTask
TaskName="GitVersionTask.UpdateNativeVersionHeader"
AssemblyFile="$(GitVersionTaskLibrary)GitVersionTask.dll" />
<UsingTask
TaskName="GitVersionTask.GenerateGitVersionInformation"
AssemblyFile="$(GitVersionTaskLibrary)GitVersionTask.dll" />
Expand Down Expand Up @@ -76,7 +85,25 @@
</ItemGroup>
</Target>

<Target Name="GenerateGitVersionInformation" BeforeTargets="CoreCompile" Condition="$(GenerateGitVersionInformation) == 'true'">
<Target Name="UpdateNativeHeader" BeforeTargets="CoreCompile;ClCompile" Condition="$(UpdateNativeHeader) == 'true'">
<UpdateNativeVersionHeader
SolutionDirectory="$(GitVersionPath)"
NoFetch="$(GitVersion_NoFetchEnabled)"
ProjectFile="$(MSBuildProjectFullPath)"
IntermediateOutputPath="$(ProjectDir)"
Language="$(Language)"
CompileFiles ="@(Compile)">
<Output
TaskParameter="HeaderTempFilePath"
PropertyName="HeaderTempFilePath" />
</UpdateNativeVersionHeader>

<ItemGroup>
<Compile Include="$(AssemblyInfoTempFilePath)" />
</ItemGroup>
</Target>

<Target Name="GenerateGitVersionInformation" BeforeTargets="CoreCompile;ClCompile" Condition="$(GenerateGitVersionInformation) == 'true'">
<GenerateGitVersionInformation
SolutionDirectory="$(GitVersionPath)"
NoFetch="$(GitVersion_NoFetchEnabled)"
Expand All @@ -94,7 +121,7 @@
</ItemGroup>
</Target>

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

<GetVersion SolutionDirectory="$(GitVersionPath)" NoFetch="$(GitVersion_NoFetchEnabled)">
<Output TaskParameter="Major" PropertyName="GitVersion_Major" />
Expand Down
31 changes: 31 additions & 0 deletions src/GitVersionTask/SupportedLanguageConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace GitVersionTask
{
internal static class SupportedLanguageConstants
{
internal const string VBDOTNET = "VB";
internal const string FSHARP = "F#";
internal const string CSHARP = "C#";
internal const string CPLUSPLUS = "C++";

internal static readonly string[] SUPPORTED_LANGUAGES =
{
VBDOTNET,
CSHARP,
FSHARP,
CPLUSPLUS,
};

internal const string FILEEXTENSION_VBDOTNET = "vb";
internal const string FILEEXTENSION_CSHARP = "cs";
internal const string FILEEXTENSION_FSHARP = "fs";
internal const string FILEEXTENSION_CPLUSPLUS = "h";

internal static readonly string[] SUPPORTED_LANGUAGE_FILEEXTENSIONS =
{
FILEEXTENSION_VBDOTNET,
FILEEXTENSION_CSHARP,
FILEEXTENSION_FSHARP,
FILEEXTENSION_CPLUSPLUS,
};
}
}
12 changes: 6 additions & 6 deletions src/GitVersionTask/UpdateAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ string GetFileExtension()
{
switch(Language)
{
case "C#":
return "cs";
case SupportedLanguageConstants.CSHARP:
return SupportedLanguageConstants.FILEEXTENSION_CSHARP;

case "F#":
return "fs";
case SupportedLanguageConstants.FSHARP:
return SupportedLanguageConstants.FILEEXTENSION_FSHARP;

case "VB":
return "vb";
case SupportedLanguageConstants.VBDOTNET:
return SupportedLanguageConstants.FILEEXTENSION_VBDOTNET;

default:
throw new Exception($"Unknown language detected: '{Language}'");
Expand Down
Loading