Skip to content

[Bug]Build error due to malformed file path obj\/gitversion.json #2534

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
NameOfTheDragon opened this issue Jan 13, 2021 · 16 comments · Fixed by #2547
Closed

[Bug]Build error due to malformed file path obj\/gitversion.json #2534

NameOfTheDragon opened this issue Jan 13, 2021 · 16 comments · Fixed by #2547
Labels
Milestone

Comments

@NameOfTheDragon
Copy link

Describe the bug
GitVersion.MSBuild nuget package v5.6.3 uses a badly formed path that causes a build error.
The build log makes this clear:

C:\Users\Tim\.nuget\packages\gitversion.msbuild\5.6.3\tools\GitVersion.MsBuild.targets: The command "C:\Users\Tim\.nuget\packages\gitversion.msbuild\5.6.3\tools\net48/gitversion.exe C:\Users\Tim\AppData\Local\NCrunch\12004\2\TA.Ascom.ReactiveCommunications -output file -outputfile obj\/gitversion.json" exited with code 1.

Expected Behavior

Obviously, there should not be a build error

Steps to Reproduce

  1. Add NuGet packae GitVersion.MSBuild-5.3.6 to a NETStandard 2.1 class library project.
  2. Build the project
  3. Observe the build error.

Context

Showstopper! I can no longer build my code.

Your Environment

Windows 10
VS2019 Enterprise
.NETStandard 2.1 class library project
GitVersion.MSBuild nuget package v5.6.3

Here is a link to the minimal solution required to reproduce the issue (it is really just File/New Project)
https://github.com/NameOfTheDragon/TA.GitVersionIssue

@NameOfTheDragon
Copy link
Author

NameOfTheDragon commented Jan 13, 2021

Sorry guys, false alarm. Something else must've been going on as I can't reproduce it now after reloading VS. You still might want to look at that mangled path though ;-)

@asbjornu
Copy link
Member

There may be hard coded instances of \ or / in our codebase which should be replaced with calls to Path.Combine(). Pull requests are welcome! 😃 🙏🏼

@arturcic
Copy link
Member

@asbjornu this one is done in msbuild props

<GitVersionOutputFile>$(BaseIntermediateOutputPath)/gitversion.json</GitVersionOutputFile>

@arturcic
Copy link
Member

arturcic commented Jan 13, 2021

maybe we need to remove the/, as the BaseIntermediateOutputPath has already the correct \ or /

@asbjornu
Copy link
Member

asbjornu commented Jan 13, 2021

Ah, we should replace that with $([System.IO.Path]::Combine($(BaseIntermediateOutputPath), 'gitversion.json')) if possible.

@asbjornu
Copy link
Member

maybe we need to remove the/, as the BaseIntermediateOutputPath has already the correct \ or /

That's a good point and may highlight why Microsoft designed all paths to deliberately end with slashes in MSBuild. I've always despised that decision, but alleviating the need to do Path.Combine is a neat feature I haven't realized before.

arturcic added a commit to arturcic/GitVersion that referenced this issue Jan 13, 2021
arturcic added a commit to arturcic/GitVersion that referenced this issue Jan 13, 2021
@bddckr
Copy link
Contributor

bddckr commented Jan 13, 2021

I believe just dropping the slash is exactly what the MSBuild convention is, considering this property is documented to end with the slash here.

If you want to guard against users who override this property but forget to add the slash at the end I suggest $([MSBuild]::EnsureTrailingSlash($(BaseIntermediateOutputPath)), which uses one of the property functions. I've personally ran into a bunch of other targets that don't handle missing slashes for properties that represent directory paths, so I still prefer just requiring users to get it right.

@arturcic
Copy link
Member

@bddckr do you mind sending a PR?

@bddckr
Copy link
Contributor

bddckr commented Jan 13, 2021

👍 However, I'll check out the provided repro later today or tomorrow first - I've not been able to reproduce in my own projects at all 🤔 (I already had the slash at the end for this property, but even removing it doesn't change anything - it keeps working for me no matter what.)

@julianbartel
Copy link
Contributor

julianbartel commented Jan 13, 2021

Hi all,
I ran into the same issue, but for me, it was not the malformed GitVersionOutputFile property but the GitVersionFileExe property.

<GitVersionFileExe Condition="'$(GitVersionFileExe)' == ''">dotnet --roll-forward Major $(MSBuildThisFileDirectory)netcoreapp3.1/gitversion.dll</GitVersionFileExe>

The path should be quoted, otherwise the call fails when the package is cached in a path containing whitespaces (on Windows, this is usually %userprofile%.nuget\packages - I my case, having a space in my user name).

After changing this to dotnet --roll-forward Major &quot;$(MSBuildThisFileDirectory)netcoreapp3.1/gitversion.dll&quot; it worked as expected.

@SeppPenner
Copy link

I have this issue as well. My project under https://github.com/SeppPenner/SerilogSinkForPostgreSQL (With multiple target frameworks) throws the error: Der Befehl "C:\Users\User\.nuget\packages\gitversion.msbuild\5.6.3\tools\net48/gitversion.exe C:\Users\User\Github\C# und VB\SerilogSinkForPostgreSQL\src\SerilogSinksPostgreSQL -output file -outputfile obj\/gitversion.json" wurde mit dem Code 1 beendet.

@arturcic I will try your change from arturcic@353837a and see if this works for me.

@SeppPenner
Copy link

SeppPenner commented Jan 14, 2021

Ok, the workaround doesn't solve my issue.

I have tried to change

<PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Full' Or '$(MSBuildRuntimeType)' == 'Mono'">
    <GitVersionFileExe>$(MSBuildThisFileDirectory)net48/gitversion.exe</GitVersionFileExe>
    <GitVersionAssemblyFile>$(MSBuildThisFileDirectory)net48/GitVersion.MsBuild.dll</GitVersionAssemblyFile>
</PropertyGroup>

to

<PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Full' Or '$(MSBuildRuntimeType)' == 'Mono'">
    <GitVersionFileExe>$(MSBuildThisFileDirectory)net48\gitversion.exe</GitVersionFileExe>
    <GitVersionAssemblyFile>$(MSBuildThisFileDirectory)net48\GitVersion.MsBuild.dll</GitVersionAssemblyFile>
</PropertyGroup>

However, this doesn't help either, the error stays the same.

EDIT: I agree with @julianbartel, my path has a space in it...

@thoemmi
Copy link
Contributor

thoemmi commented Jan 15, 2021

Is there any known workaround? I've added

<PropertyGroup>
  <GitVersionOutputFile>$(BaseIntermediateOutputPath)gitversion.json</GitVersionOutputFile>
  <GitVersion_ToolArgments>-output file -outputfile $(GitVersionOutputFile)</GitVersion_ToolArgments>
</PropertyGroup>

in my Directory.Build.props, but it didn't help.

@asbjornu
Copy link
Member

The best "workaround" is to provide a pull request that fixes this in GitVersion.

@SeppPenner
Copy link

The best "workaround" is to provide a pull request that fixes this in GitVersion.

If I knew where the problem was, there would have been one from my side :D

@arturcic arturcic added this to the 5.6.4 milestone Jan 19, 2021
@github-actions
Copy link

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

Your GitReleaseManager bot 📦🚀

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 a pull request may close this issue.

7 participants