Skip to content
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
26 changes: 25 additions & 1 deletion build/artifacts/Tasks/ArtifactsMsBuildFullTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ public override void Run(BuildContext context)
if (context.Version == null)
return;
var version = context.Version.NugetVersion;
var fullSemVer = context.Version.GitVersion.FullSemVer;

var nugetSource = context.MakeAbsolute(Paths.Nuget).FullPath;

const int toolVersionValue = 11; // Workaround for now. It should be removed when https://github.com/cake-build/cake/issues/4658 is merged
var isMsBuildToolVersionValid = Enum.IsDefined(typeof(MSBuildToolVersion), toolVersionValue);

context.Information("\nTesting msbuild task with dotnet build\n");
foreach (var netVersion in Constants.DotnetVersions)
{
Expand All @@ -40,7 +44,27 @@ public override void Run(BuildContext context)
});

var exe = Paths.Integration.Combine("build").Combine(framework).CombineWithFilePath("app.dll");
context.ValidateOutput("dotnet", exe.FullPath, context.Version.GitVersion.FullSemVer);
context.ValidateOutput("dotnet", exe.FullPath, fullSemVer);

if (!isMsBuildToolVersionValid) continue;

const MSBuildToolVersion toolVersion = (MSBuildToolVersion)toolVersionValue;
context.Information("\nTesting msbuild task with msbuild (for full framework)\n");

var msBuildSettings = new MSBuildSettings
{
Verbosity = Verbosity.Minimal,
ToolVersion = toolVersion,
Restore = true
};

msBuildSettings.WithProperty("GitVersionMsBuildVersion", version);
msBuildSettings.WithProperty("RestoreSource", nugetSource);

context.MSBuild(projPath.FullPath, msBuildSettings);

var fullExe = Paths.Integration.Combine("build").CombineWithFilePath("app.exe");
context.ValidateOutput(fullExe.FullPath, null, fullSemVer);
}
}
}
4 changes: 3 additions & 1 deletion src/GitVersion.Core/Extensions/ReferenceNameExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public bool TryGetSemanticVersion(IGitVersionConfiguration configuration, out Se

private bool TryGetSemanticVersion(string? versionPatternPattern,
string? tagPrefix,
SemanticVersionFormat format, out SemanticVersionResult result)
SemanticVersionFormat format,
// ReSharper disable once OutParameterValueIsAlwaysDiscarded.Local
out SemanticVersionResult result)
{
var versionPatternRegex = RegexPatterns.Cache.GetOrAdd(GetVersionInBranchPattern(versionPatternPattern));
result = default;
Expand Down
12 changes: 6 additions & 6 deletions src/GitVersion.MsBuild/GitVersionTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ public static bool Execute(GitVersionTaskBase task)
var executor = serviceProvider.GetRequiredService<IGitVersionTaskExecutor>();
return task switch
{
GetVersion getVersion => ExecuteGitVersionTask(getVersion, () => executor.GetVersion(getVersion)),
UpdateAssemblyInfo updateAssemblyInfo => ExecuteGitVersionTask(updateAssemblyInfo, () => executor.UpdateAssemblyInfo(updateAssemblyInfo)),
GenerateGitVersionInformation generateGitVersionInformation => ExecuteGitVersionTask(generateGitVersionInformation, () => executor.GenerateGitVersionInformation(generateGitVersionInformation)),
WriteVersionInfoToBuildLog writeVersionInfoToBuildLog => ExecuteGitVersionTask(writeVersionInfoToBuildLog, () => executor.WriteVersionInfoToBuildLog(writeVersionInfoToBuildLog)),
GetVersion getVersion => ExecuteGitVersionTask(getVersion, executor.GetVersion),
UpdateAssemblyInfo updateAssemblyInfo => ExecuteGitVersionTask(updateAssemblyInfo, executor.UpdateAssemblyInfo),
GenerateGitVersionInformation generateGitVersionInformation => ExecuteGitVersionTask(generateGitVersionInformation, executor.GenerateGitVersionInformation),
WriteVersionInfoToBuildLog writeVersionInfoToBuildLog => ExecuteGitVersionTask(writeVersionInfoToBuildLog, executor.WriteVersionInfoToBuildLog),
_ => throw new NotSupportedException($"Task type {task.GetType().Name} is not supported")
};
}

private static bool ExecuteGitVersionTask<T>(T task, Action action)
private static bool ExecuteGitVersionTask<T>(T task, Action<T> action)
where T : GitVersionTaskBase
{
var taskLog = task.Log;
try
{
action();
action(task);
}
catch (WarningException errorException)
{
Expand Down
8 changes: 4 additions & 4 deletions src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
</PropertyGroup>

<PropertyGroup>
<!-- The GitVersion task is explicitly disabled when running on the .NET Framework because it's no longer supported.
If a project that uses GitVersion.MsBuild is opened in Visual Studio,
<!-- The GitVersion task is explicitly disabled when running on the .NET Framework with MSBuild version lower than 18
or in Visual Studio 2022 or earlier (which uses MSBuild version 17 and below). In these scenarios,
the task will be turned off because Visual Studio operates on the .NET Framework's version of MSBuild.
However, you can still execute GitVersion.MsBuild as part of the `dotnet build` or `dotnet msbuild` commands. -->
<DisableGitVersionTask Condition=" '$(MSBuildRuntimeType)' != 'Core' ">true</DisableGitVersionTask>
However, it is supported from msbuild version 18 or Visual Studio 2026, or using the .NET version `dotnet build` -->
<DisableGitVersionTask Condition=" '$(MSBuildRuntimeType)' == 'Full' AND $([System.Version]::Parse('$(MSBuildVersion)').Major) &lt; 18 ">true</DisableGitVersionTask>

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

Expand Down
13 changes: 9 additions & 4 deletions src/GitVersion.MsBuild/msbuild/tools/GitVersion.MsBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
<GitVersionAssemblyFile Condition="'$(GitVersionAssemblyFile)' == ''">$([MSBuild]::EnsureTrailingSlash($(MSBuildThisFileDirectory)$(GitVersionTargetFramework)))GitVersion.MsBuild.dll</GitVersionAssemblyFile>
</PropertyGroup>

<UsingTask TaskName="GetVersion" AssemblyFile="$(GitVersionAssemblyFile)" />
<UsingTask TaskName="GenerateGitVersionInformation" AssemblyFile="$(GitVersionAssemblyFile)" />
<UsingTask TaskName="WriteVersionInfoToBuildLog" AssemblyFile="$(GitVersionAssemblyFile)" />
<UsingTask TaskName="UpdateAssemblyInfo" AssemblyFile="$(GitVersionAssemblyFile)" />
<UsingTask TaskName="GetVersion" AssemblyFile="$(GitVersionAssemblyFile)" Runtime="NET" TaskFactory="TaskHostFactory" Condition=" '$(MSBuildRuntimeType)' == 'Full' " />
<UsingTask TaskName="GenerateGitVersionInformation" AssemblyFile="$(GitVersionAssemblyFile)" Runtime="NET" TaskFactory="TaskHostFactory" Condition=" '$(MSBuildRuntimeType)' == 'Full' " />
<UsingTask TaskName="WriteVersionInfoToBuildLog" AssemblyFile="$(GitVersionAssemblyFile)" Runtime="NET" TaskFactory="TaskHostFactory" Condition=" '$(MSBuildRuntimeType)' == 'Full' " />
<UsingTask TaskName="UpdateAssemblyInfo" AssemblyFile="$(GitVersionAssemblyFile)" Runtime="NET" TaskFactory="TaskHostFactory" Condition=" '$(MSBuildRuntimeType)' == 'Full' " />

<UsingTask TaskName="GetVersion" AssemblyFile="$(GitVersionAssemblyFile)" Runtime="NET" Condition=" '$(MSBuildRuntimeType)' == 'Core' " />
<UsingTask TaskName="GenerateGitVersionInformation" AssemblyFile="$(GitVersionAssemblyFile)" Runtime="NET" Condition=" '$(MSBuildRuntimeType)' == 'Core' " />
<UsingTask TaskName="WriteVersionInfoToBuildLog" AssemblyFile="$(GitVersionAssemblyFile)" Runtime="NET" Condition=" '$(MSBuildRuntimeType)' == 'Core' " />
<UsingTask TaskName="UpdateAssemblyInfo" AssemblyFile="$(GitVersionAssemblyFile)" Runtime="NET" Condition=" '$(MSBuildRuntimeType)' == 'Core' " />

<Target Name="RunGitVersion" Condition="'$(DisableGitVersionTask)' == 'false'">
<Exec Command="$(GitVersionFileExe) &quot;$(MSBuildProjectDirectory)&quot; $(GitVersion_ToolArgments)" />
Expand Down
Loading