1

I am trying to save a git command output to a file before compiling, of an asp.net-core project.

In the "project.json" file I have the following, which should output the latest git tag to an output file (for versioning):

  "scripts": {
        "precompile": [
          "git describe --tags > version.txt"
        ]
      },

The git command runs fine in normal git bash and saves to a file. But when I compile the project in Visual Studio, there seems to be an issue with that greater than symbol. Should this be escaped somehow? The error shows: "fatal: Not a valid object name >"

Full error: "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(262,5): error : fatal: Not a valid object name >"

Any ideas?

David Smit
  • 829
  • 1
  • 13
  • 31

3 Answers3

1

Please try to create cmd-script (i.e. update_version.cmd) containing the same command:

git describe --tags > version.txt

Update your project.json:

"scripts": {
    "precompile": "update_version.cmd"
  },
Ivan
  • 3,084
  • 4
  • 21
  • 22
  • this works thanks a lot! I will mark this as answer soon, just waiting if someone perhaps know if this can be done without creating a command file (just run it in one command in scripts) – David Smit Dec 06 '16 at 11:54
1

Have you tried

  "scripts": {
    "precompile": [
      "bash -c 'git describe --tags > version.txt'"
    ]
  },
GlennSills
  • 3,977
  • 26
  • 28
  • Oh wait I see bash is installed with Git for Windows! Let me quickly test – David Smit Dec 07 '16 at 07:41
  • Great this worked! It doesn't look like 'bash' is added to the enviroment variable by default when installing Git Windows, so the only change I made to your snipped is referencing the bash exe like so: "%ProgramFiles%\\Git\\bin\\bash.exe -c 'git describe --tags > version.txt'" – David Smit Dec 07 '16 at 07:46
0

What I ended up doing is a bit what Ivan suggested i.e. running a cmd script, but also generating a JSON file with the version number.

This is perhaps better than a normal text file because the Json can be read from the new Configure Options (OptionsConfigurationServiceCollectionExtensions) in dotnet core.

Not an exact answer to the question, but might help someone else. Here is the CMD to generate the appsettingsversion.json file:

project.json:

"scripts": {
    "prepublish": [ "bower install", "dotnet bundle", "update_version.cmd" ]
  }

update_version.cmd:

for /f %%i in ('git describe --tags') do set version=%%i
echo {^"VersionSettings^":{^"Number^": ^"%version%^"}}  > appsettingsversion.json
David Smit
  • 829
  • 1
  • 13
  • 31