Search code examples
c#.netgitgitversion

dotnet-gitversion "ShortSha" /updateassemblyinfo : Cannot find the .git directory


As explained in this previous question, I would like to add the commit hash of my sources to my executable or DLL.

In order to do this, I would like to work with the following command:

dotnet-gitversion "ShortSha" /updateassemblyinfo

I have already created a FixedAssemblyInfo.cs in order to protect the rest of my [assembly] tags, but now when I try to run the mentioned command, I get the error message:

Cannot find the .git directory

I have launched the command in different ways:

  • In the main directory of my Visual Studio solution, where the .git directory is present.
  • In the subdirectory of my Visual Studio project, some subdirectory levels under the directory where the .git directory is present.
  • Generally the .git directory is hidden. I have unchecked the Hidden checkbox in that directory's details, but no luck.
  • I have launched dotnet-gitversion from a command prompt, a command prompt, run as administrator, and from the "Developer Command Prompt for VS 2017".

Now, you can guess, it's my idea to add the dotnet-gitversion "ShortSha" /updateassemblyinfo command as a pre-build event, but if I can't even run it as a simple command, how can I launch it as a pre-build event?

For your information, the full pre-build event looks as follows:

cd $(ProjectDir)
dotnet-gitversion "ShortSha" /updateassemblyinfo

Does anybody have an idea?

O, before I forget: what I'm trying to achieve, is simply the creation of the AssemblyInfo.cs file, containing (at least) the "ShortSha" of my source code. In top of this I would like to have it as a pre-build event, in order to have this information, every time I compile my project.

Thanks a lot in advance


Solution

  • If I read the doc correctly : dotnet-gitversion interprets its first argument as the path to the root of the project. ShortSha doesn't fit the bill.

    You probably want to use the /showvariable option, which indicates to also set /output json.