It’s not a duplicate! I think I tried what I could find in the internet but it didn’t help.
I’m using Visual Studio 2022.
I added the following in Project
element of my .Net Core project’s file to add git commit hash into to details of an executable file. And, it worked. But, when I add the same Target
element into my .Net Framework project it does not add git commit hash.
I tried this, but it didn’t help. The Build
button dissapears when I use this custom AssemblyInfoGenerationSdk
.
Did anyone found a workaround? Is there any other way to add git commit has into to details of an executable file?
<Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation">
<Exec Command="git describe --long --always --dirty --exclude=* --abbrev=8" ConsoleToMSBuild="True" IgnoreExitCode="False">
<Output PropertyName="SourceRevisionId" TaskParameter="ConsoleOutput" />
</Exec>
</Target>
Projects
I created a solution with 3 projects:
- ConsoleApp1_NetCore: .Net Core project
- ConsoleApp2_NetFramework: .Net Framework project
- ConsoleApp3_NetCoreTargetsNetFramework: .Net Core project but I manually modified the project’s file to target .Net Framework 472 (
<TargetFramework>net472</TargetFramework>
)
The git hash gets generated for projects 1 and 3 since they both have <Project Sdk="Microsoft.NET.Sdk">
. But, not for project 2 which is not Sdk
project. The solution with the projects is physically located in a git folder.
The msbuild
exec
task doesn’t change with the target framework. If you run the git command in the directory of your .Net Framework project, what is the result? Is the .Net Framework project in a git repo?What do you mean? Here is the post for non-sdk project stackoverflow.com/questions/58920312/…
Forget about
AssemblyInfoGenerationSdk
. It can’t solve your issue. The git commit hash is not an assembly attribute.@JonathanDodds, what can I do then?
The
Exec
task is a standard task in MSBuild. Its behavior is the same in legacy style .NET Framework projects and SDK style projects.Show 3 more comments