C
C#13mo ago
Nacio

❔ Saving current commit information to a file

I'm trying to save the current commit's information using this in the .csproj
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="git log -1 --pretty=%&lt;25&gt;H%&lt;25&gt;n%&lt;25&gt;an%&lt;25&gt;n%&lt;25&gt;ae%&lt;25&gt;n%&lt;25&gt;cn%&lt;25&gt;n%&lt;25&gt;ce%&lt;25&gt;n%&lt;25&gt;cI%&lt;25&gt;n%&lt;25&gt;s &gt; &quot;$(ProjectDir)\CurrentCommit&quot;"/>
</Target>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="git log -1 --pretty=%&lt;25&gt;H%&lt;25&gt;n%&lt;25&gt;an%&lt;25&gt;n%&lt;25&gt;ae%&lt;25&gt;n%&lt;25&gt;cn%&lt;25&gt;n%&lt;25&gt;ce%&lt;25&gt;n%&lt;25&gt;cI%&lt;25&gt;n%&lt;25&gt;s &gt; &quot;$(ProjectDir)\CurrentCommit&quot;"/>
</Target>
but it just keeps saying The system cannot find the file specified., does that mean it can't find the git command or actually the file, or maybe there's a better way to get the commit info? git log -1 --pretty=%H%n%an%n%ae%n%cn%n%ce%n%cI%n%s > ".\CurrentCommit" works just fine when run in a regular terminal Build log: https://pastebin.com/raw/2dpKPdq5
8 Replies
ero
ero13mo ago
can you try MSBuildProjectDir instead
Nacio
Nacio13mo ago
Makes the path /CurrentCommit and same message
ero
ero13mo ago
what's with all those &lt; and &gt; in the git command? git log -1 --pretty=%H%n%an%n%ae%n%cn%n%ce%n%cI%n%s > ".\CurrentCommit" doesn't feature those at all
Nacio
Nacio13mo ago
Escaping % % escaped is %<25> afaik
ero
ero13mo ago
that would surprise me very much
Nacio
Nacio13mo ago
git log -1 --pretty=%H%n%an%n®%n%cn%nÎ%n%cI%n%s > "\CurrentCommit"
fatal: invalid --pretty format: nn®cnnns
git log -1 --pretty=%H%n%an%n®%n%cn%nÎ%n%cI%n%s > "\CurrentCommit"
fatal: invalid --pretty format: nn®cnnns
ero
ero13mo ago
yeah seems like an issue for dotnet/msbuild i tried around with it a bunch and somehow the exec task can't get the correct format
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.