Skip to content

Conversation

@arturcic
Copy link
Member

@arturcic arturcic commented Nov 17, 2025

This pull request introduces several improvements to how MSBuild tasks are configured and executed for different .NET runtimes, as well as some code cleanups and minor refactorings. The main focus is on ensuring correct task registration and execution for both .NET Core and .NET Framework, improving maintainability, and removing outdated configuration. Below are the most important changes grouped by theme.

MSBuild Task Registration and Runtime Handling:

  • Updated GitVersion.MsBuild.targets to register MSBuild tasks (GetVersion, GenerateGitVersionInformation, WriteVersionInfoToBuildLog, UpdateAssemblyInfo) separately for .NET Core and .NET Framework, using appropriate conditions and task factories for each runtime. This ensures tasks are loaded correctly depending on the build environment.

  • Removed the legacy property disabling GitVersion tasks on .NET Framework from GitVersion.MsBuild.props, cleaning up the configuration and clarifying task enablement logic.

Build Task Execution and Validation Improvements:

  • In ArtifactsMsBuildFullTest.cs, added logic to check for a specific MSBuildToolVersion before running full framework tests, and refactored output validation to use a locally scoped fullSemVer variable for clarity and correctness. [1] [2]

Code Refactoring and Cleanup:

  • Refactored GitVersionTasks.cs to simplify task execution by passing the task instance directly to the executor methods, improving readability and maintainability.

  • Minor code comment and annotation improvements in ReferenceNameExtensions.cs to clarify out parameter usage.

  • NOTE: this will work only when working on VS 2026 or msbuild 18. Lower versions are no supported.

Resolves #4130

@arturcic arturcic force-pushed the feature/msbuild-task branch 2 times, most recently from d27c90d to 98f9ecf Compare November 18, 2025 00:32
@arturcic arturcic marked this pull request as ready for review November 18, 2025 00:57
Copilot AI review requested due to automatic review settings November 18, 2025 00:57
Copilot finished reviewing on behalf of arturcic November 18, 2025 00:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR re-enables MSBuild task support for .NET Framework builds when running on MSBuild version 18+ (Visual Studio 2026 and later), while maintaining compatibility with .NET Core builds. Previously, GitVersion tasks were completely disabled on .NET Framework; now they are conditionally enabled based on MSBuild version.

Key changes:

  • Conditional task registration based on MSBuildRuntimeType with appropriate TaskFactory settings
  • Updated disable condition to only block on MSBuild versions < 18 for Full Framework
  • Refactored task execution to use method group references instead of lambda closures

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
GitVersion.MsBuild.targets Splits UsingTask declarations for Full Framework (with TaskHostFactory) and Core runtime
GitVersion.MsBuild.props Updates DisableGitVersionTask condition to allow MSBuild 18+ on Full Framework
GitVersionTasks.cs Simplifies task executor invocation by passing task instances directly
ReferenceNameExtensions.cs Adds ReSharper suppression comment for out parameter
ArtifactsMsBuildFullTest.cs Adds MSBuild Full Framework testing when MSBuildToolVersion 11 is available

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@arturcic arturcic force-pushed the feature/msbuild-task branch from 98f9ecf to bd44563 Compare November 18, 2025 06:26
@arturcic arturcic added this to the 6.x milestone Nov 18, 2025
@arturcic arturcic requested a review from asbjornu November 18, 2025 09:37
@arturcic
Copy link
Member Author

This was tested on a windows machine running in a VM with a Visual Studio 2026 running a sample application (which is part of a git repo) and this piece of code:

Console.WriteLine(GitVersionInformation.Sha);

It compiled and when run get the sha of the commit.

Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

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

Although I don't use it anymore myself, it's awesome to have VS support back!

adapts msbuild tasks execution to use action with task parameter.
removes net framework check on GitVersionTask.
adds condition to msbuild targets.
This enabled testing the GitVersion.MsBuild with the full .NET Framework's version of msbuild
disables GitVersion task on .NET Framework with MSBuild < 18.
updates conditions for UsingTask to use explicit string comparisons.
@arturcic arturcic force-pushed the feature/msbuild-task branch from bd44563 to 9aa4c70 Compare November 18, 2025 11:32
@sonarqubecloud
Copy link

@arturcic arturcic merged commit a7213ac into GitTools:main Nov 18, 2025
118 checks passed
@arturcic arturcic deleted the feature/msbuild-task branch November 18, 2025 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants