Reputation: 2554
My goal: To run dotnet gitversion /updateprojectfiles
as part of the build.
My limitations: not all machines have gitversion
installed, so I need to install it on those without. However, Microsoft's dotnet tool install
will return the code 1 when attempting to install a tool that is already installed. So I need to first check if it is installed, and only if it isn't, install it.
My first solution: Write a batch file and call it from the prebuild script.
The complication: Some of the machines building the code are linux, and do not recognize batch files.
My question: How can I write my logic as part of the pre-build commands, in a way that will work on both windows and linux?
The code: gitversion-up-to-date.cmd:
FOR /F "tokens=* USEBACKQ" %%F IN (`dotnet tool list -g ^| findstr gitversion.tool`) DO (
SET "grep=TRUE"
)
if %grep%==TRUE goto setVersion
dotnet tool install -g GitVersion.Tool
setVersion
:setVersion
dotnet gitversion /updateprojectfiles
and then from the csproj prebuild:
$(SolutionDir)gitversion-up-to-date.cmd
How can I write this logic, preferably directly in the prebuild, in a way that will work on both windows and linux?
My biggest issue atm is understanding how to write the logic for finding whether the tool is already installed.
TIA!
Upvotes: 3
Views: 1145