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

Add GitVersion_CommandLineArguments parameter to MSBuild task #3022

Merged
merged 3 commits into from
Jul 19, 2022

Conversation

professor-k
Copy link
Contributor

@professor-k professor-k commented Mar 2, 2022

Implemented generic way to pass arbitrary command line parameter for GetVersion.

Description

This parameter allows to pass arbitrary string which is then literally passed down to Exec.

Related Issue

Fixes #3021.

Motivation and Context

Allows to pass in arbitrary extra parameters with just one parameter

How Has This Been Tested?

Couple manual runs with or without this parameter, both via dotnet/msbuild command line /p key, and via variable declaration in the csproj file. I looked into the code and it doesn't look like there is anything to test msbuild scripts per se. As for C# code I didn't touch it (to be fair, I wasn't even able to open solution, as VS 2022 was hanging every time I was trying to do so).

As for documentation, I got Error: The target 'Preview-Documentation' was not found.. Something must be broken. Anyway, I wrote couple lines section in documentation for MsBuild GetVersion configuration, and it looks okay when viewed via GitHub. Just make sure to proofread, as I'm not a native speaker.

Screenshots (if appropriate):

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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.

I think this is a welcome change, especially the added documentation, but the title of the PR seems to be wrong (should probably say Added GitVersion_CommandLineArguments parameter to MSBuild task) and I would love to have a test added for this. You can see some tests exercising the MSBuild Task here:

[Test]
public void GetVersionTaskShouldReturnVersionOutputVariables()
{
var task = new GetVersion();
using var result = ExecuteMsBuildTask(task);
result.Success.ShouldBe(true);
result.Errors.ShouldBe(0);
result.Task.Major.ShouldBe("1");
result.Task.Minor.ShouldBe("2");
result.Task.Patch.ShouldBe("4");
result.Task.MajorMinorPatch.ShouldBe("1.2.4");
result.Task.FullSemVer.ShouldBe("1.2.4+1");
}

@asbjornu asbjornu changed the title Added GitVersion_Config parameter to MSBuild task Add GitVersion_CommandLineArguments parameter to MSBuild task Mar 9, 2022
@arturcic arturcic changed the base branch from main to support/5.x March 12, 2022 15:26
@professor-k
Copy link
Contributor Author

@asbjornu yes, you are correct about the pull request name. I had two branches, and was considering making pull request for Config override too.

As for MSBuild script tests. Looked into code once again, and still don't see easy way to do it. Test you pointed out tests MSBuild Task directly without even touching MSBuild scripts. Yet my changes are in .props file and even more, they are not affecting GetVersion task, they are affecting parameters of the Exec task.

Well, I have some idea how to do this: there are other tests that create .csproj and run msbuild on it. I would probably build on that by injecting both .props and .targets into blank .csproj in order to mimic what nuget reference does. But then I would need to find compiled gitversion.dll, which would probably involve adding dependency on GitVersion.App to tests. And it would test way more than just adding one parameter that is then literally passed down to Exec. Nothing impossible, but 1) feels way out of scope of this pull request. 2) Changing architecture of solution is not something I like to do on my own initiative in my first pull request on project I'm just getting myself familiarized with :)

@asbjornu
Copy link
Member

I agree that the amount of heavy lifting you're describing is a bit much to ask for in a first contributor PR, @professor-k. I do have a feeling we have or at least had something along the lines you describe in place, though. Do you know, @arturcic?

@stale
Copy link

stale bot commented Jun 12, 2022

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 12, 2022
@asbjornu asbjornu merged commit 8f85fab into GitTools:support/5.x Jul 19, 2022
@asbjornu asbjornu added this to the 5.x milestone Jul 19, 2022
@mergify
Copy link
Contributor

mergify bot commented Jul 19, 2022

Thank you @professor-k for your contribution!

@arturcic arturcic added improvement and removed stale labels Nov 7, 2022
@arturcic arturcic modified the milestones: 5.x, 5.11.0 Nov 7, 2022
@arturcic
Copy link
Member

arturcic commented Nov 7, 2022

🎉 This issue has been resolved in version 5.11.0 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

@phitattoo
Copy link

Implemented generic way to pass arbitrary command line parameter for GetVersion.

Description

This parameter allows to pass arbitrary string which is then literally passed down to Exec.

Related Issue

Fixes #3021.

Motivation and Context

Allows to pass in arbitrary extra parameters with just one parameter

How Has This Been Tested?

Couple manual runs with or without this parameter, both via dotnet/msbuild command line /p key, and via variable declaration in the csproj file. I looked into the code and it doesn't look like there is anything to test msbuild scripts per se. As for C# code I didn't touch it (to be fair, I wasn't even able to open solution, as VS 2022 was hanging every time I was trying to do so).

As for documentation, I got Error: The target 'Preview-Documentation' was not found.. Something must be broken. Anyway, I wrote couple lines section in documentation for MsBuild GetVersion configuration, and it looks okay when viewed via GitHub. Just make sure to proofread, as I'm not a native speaker.

Screenshots (if appropriate):

Checklist:

  • My code follows the code style of this project.

  • My change requires a change to the documentation.

  • I have updated the documentation accordingly.

  • I have added tests to cover my changes.

  • All new and existing tests passed.

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

Successfully merging this pull request may close these issues.

[Feature] Allow to pass extra command line parameters to MSBuild task
4 participants