ThisAssembly.Git exception when project has Git submodule
Describe the Bug
ThisAssembly.Git produces a build error when solution has Git submodules
ThisAssembly.Git.targets(71,7): error MSB4184: The expression "[System.IO.File]::ReadAllText(/path/;/path/anotherpath/.git/HEAD)" cannot be evaluated. Could not find a part of the path '/path/;/path/anotherpath/.git/HEAD'
Issue is in ThisAssembly.Git.targets line 71 $([System.IO.File]::ReadAllText
<PropertyGroup Condition="'$(RepositoryBranch)' == '' and '$(RepositoryRoot)' != ''">
<!-- We may not be in CI at all. If we got a git repo root, we can directly read HEAD -->
<RepositoryHead>$(RepositoryRoot).git/HEAD</RepositoryHead>
<RepositoryBranch Condition="Exists($(RepositoryHead))">$([System.IO.File]::ReadAllText($(RepositoryHead)).Trim())</RepositoryBranch>
<RepositoryBranch Condition="$(RepositoryBranch) != ''">$(RepositoryBranch.TrimStart("ref:").Trim().TrimStart("refs").Trim("/").TrimStart("heads").Trim("/").Trim())</RepositoryBranch>
</PropertyGroup>
I believe because @(SourceRoot) will also return submodule information
Hm. I wonder how come Exists($(RepositoryHead)) would return true and then File.ReadAllText fail? 🤔
Fix in ThisAssembly.Git.targets
<ItemGroup>
<_ThisAssemblyGitSourceRoot Include="@(SourceRoot -> WithMetadataValue('SourceControl', 'git'))"
Exclude="@(SourceRoot -> HasMetadata('NestedRoot'))" />
</ItemGroup>
Also think the build failure may be just a Linux issue. Anyway needs the change above, so that the Branch constant is set.
I believe this is fixed by your PR #334
BTW, just shipped it as 1.5.0-beta.