{
  "Header": {
    "_": [
      "https://github.com/3F/vsSolutionBuildEvent"
    ],
    "Compatibility": "0.9"
  },
  "PreBuild": [
    {
      "Enabled": true,
      "Name": "ActDir",
      "Caption": "To prepare directories",
      "SupportMSBuild": true,
      "SupportSBEScripts": true,
      "IgnoreIfBuildFailed": false,
      "BuildType": "Common",
      "Confirmation": false,
      "Mode": {
        "$type": "net.r_eg.vsSBE.Events.ModeScript, vsSolutionBuildEvent",
        "Type": "Script",
        "Command__": [
          "#[$(dbin = \"bin/Release/\")]",
          "",
          "$(odir = \"$(dbin)raw/\")",
          "",
          "#[IO delete.directory(\"$(dbin)\", true)]",
          "#[IO copy.directory(\"\", \"$(dbin)\", true)]",
          "",
          "#[$(dobj = \"obj/\")]",
          "#[IO copy.directory(\"\", \"$(dobj)\", true)]"
        ]
      }
    },
    {
      "Enabled": true,
      "Name": "ActBuild",
      "Caption": "Build core",
      "SupportMSBuild": true,
      "SupportSBEScripts": true,
      "BuildType": "Common",
      "Mode": {
        "$type": "net.r_eg.vsSBE.Events.ModeScript, vsSolutionBuildEvent",
        "Type": "Script",
        "Command__": [
          "#[$(revDeltaBase = \"2017/08/12\")]",
          "#[$(revDeltaMin  = $([System.Math]::Pow(10, 3)))]",
          "#[$(revDeltaMax  = 65534)] #[\" limit of AssemblyVersion (2^16 - 2) - i.e. 65534 max allowed \"]",
          "",
          "#[var pVer = #[File get(\".version\")]]",
          "",
          "#[\" ",
          "    Calculate revision",
          "\"]",
          "#[var tBase     = $([System.DateTime]::Parse('$(revDeltaBase)').ToBinary())]",
          "#[var tNow      = $([System.DateTime]::UtcNow.Ticks)]",
          "#[var revBuild  = #[$(",
          "                    [System.TimeSpan]::FromTicks('$(",
          "                        [MSBuild]::Subtract($(tNow), $(tBase))",
          "                    )')",
          "                    .TotalMinutes.ToString('0'))]]",
          "                     ",
          "#[var revBuild  = #[$(",
          "                    [MSBuild]::Add(",
          "                        $(revDeltaMin), ",
          "                        $([MSBuild]::Modulo(",
          "                            $(revBuild), ",
          "                            $([MSBuild]::Subtract(",
          "                                $(revDeltaMax), $(revDeltaMin)",
          "                             ))",
          "                         ))",
          "                     )",
          "                   )]",
          "]",
          "",
          "#[$(pVerPrintFile = \"$(pVer).$(revBuild)\"))]",
          "",
          "#[\" ",
          "    Checking of the git folder +tool & define sha1, branch name, etc.",
          "\"]",
          "#[var isGit = #[IO cmd(\"git rev-parse 2>&1\")]]",
          "#[( $(isGit) == \"\" )",
          "{",
          "    #[var bSha1 = #[IO sout(\"git\", \"rev-parse --short HEAD\")]]",
          "    ",
          "    #[$(pVerPrintFile = \"$(pVerPrintFile)+$(bSha1)\")]",
          "}",
          "else {",
          "    #[$(bSha1 = '-')]",
          "}]",
          "",
          "#[( $(reltype) == \"PublicRelease\" ) {",
          "    #[$(pVerPrintApp = \"$(pVer).$(revBuild)+$(bSha1)\")]",
          "}",
          "else {",
          "    #[$(pVerPrintApp = $(pVer))]",
          "}]",
          "",
          "#[\" obj \"]",
          "",
          "#[IO copy.file(\"logic.targets\", \"$(dobj)core\", true)]",
          "#[IO replace.Regex(\"$(dobj)core\", \"<GetNuTool>.*?</GetNuTool>\", \"<GetNuTool>$(pVerPrintApp)</GetNuTool>\")]",
          "",
          "#[IO writeLine(STDOUT):#[File sout(\"netmsb.bat\", \"minified/.compressor /p:core=\\\"../$(dobj)core\\\" /p:output=\\\"../$(dobj)gnt.min.core\\\" /nologo /v:m /m:4\", 400)]]",
          "",
          "#[IO writeLine(STDOUT):#[File sout(\"netmsb.bat\", \"embedded/.packer /p:core=\\\"../$(dobj)gnt.min.core\\\" /p:output=\\\"../$(dobj)gnt.bat\\\" /nologo /v:m /m:4\", 400)]]",
          "",
          "",
          "#[\" ",
          "    .compressor for executable version (batch)",
          "\"]",
          "#[IO writeLine(STDOUT):#[File sout(\"netmsb.bat\", \"embedded/.compressor /p:core=\\\"../$(dobj)gnt.bat\\\" /p:output=\\\"../$(dobj)gnt.minified.bat\\\" /nologo /v:m /m:4\", 400)]]",
          "#[IO copy.file(\"$(dobj)gnt.bat\", \"$(dobj)gnt.full.bat\", true)]",
          "#[IO copy.file(\"$(dobj)gnt.minified.bat\", \"$(dobj)gnt.bat\", true)]",
          "#[IO delete.files({\"$(dobj)gnt.minified.bat\"})]",
          "",
          "#[IO writeLine(STDOUT): Validating the generated version ...]",
          "",
          "#[IO copy.file(\"embedded/sha1*\", \"$(dobj)\", true)]",
          "#[IO writeLine(STDOUT):#[File sout(\"$(dobj)sha1.cmd\", \"\", 400)]]"
        ]
      }
    }
  ],
  "PostBuild": [
    {
      "Enabled": true,
      "Name": "ActBin",
      "Caption": "Binaries & tools ...",
      "SupportMSBuild": true,
      "SupportSBEScripts": true,
      "IgnoreIfBuildFailed": true,
      "BuildType": "Common",
      "Mode": {
        "$type": "net.r_eg.vsSBE.Events.ModeScript, vsSolutionBuildEvent",
        "Type": "Script",
        "Command__": [
          "#[IO copy.file(\"$(dobj)core\", \"$(odir)core/gnt.core\", true)]",
          "#[IO copy.file(\"$(dobj)gnt.min.core\", \"$(odir)core-minified/gnt.core\", true)]",
          "#[IO copy.file(\"$(dobj)gnt.bat\", \"$(odir)versions/01. executable/gnt.bat\", true)]",
          "#[IO copy.file(\"$(dobj)gnt.bat.map\", \"$(odir)versions/01. executable/gnt.bat.map\", true)]",
          "",
          "#[IO copy.file({",
          "                \"$(odir)core-minified/gnt.core\", ",
          "                \"caller/gnt.bat\"",
          "               }, ",
          "               \"$(odir)versions/02. wrapper/\", true)]",
          "",
          "#[IO copy.file(\"README.md\", \"$(odir)doc/Readme.md\", true)]",
          "",
          "#[IO write(\"$(odir)msbuild.bat\"):@echo off",
          "echo.",
          "echo The MSBuild-helper from GetNuTool is obsolete and was replaced by hMSBuild project.",
          "echo Please look here: https://github.com/3F/hMSBuild",
          "echo.",
          "pause",
          "]",
          "",
          "#[IO copy.file(\"changelog.txt\", \"$(odir)doc/\", true)]",
          "",
          "##[IO copy.file({",
          "                \"msbuild.bat\",",
          "                \"LICENSE\"",
          "               },",
          "               \"$(odir)\", true)]",
          "",
          "#[IO copy.file(\"LICENSE\", \"$(odir)License.txt\", true)]"
        ]
      }
    },
    {
      "Enabled": true,
      "Name": "ActZip",
      "Caption": "Create Zip archive",
      "SupportMSBuild": true,
      "SupportSBEScripts": true,
      "IgnoreIfBuildFailed": true,
      "BuildType": "Common",
      "Confirmation": false,
      "Mode": {
        "$type": "net.r_eg.vsSBE.Events.ModeScript, vsSolutionBuildEvent",
        "Type": "Script",
        "Command__": [
          "#[7z pack.directory(\"$(dbin)raw\", \"$(dbin)GetNuTool.$(pVerPrintFile).zip\")]",
          "",
          "#[IO copy.file(\"$(odir)versions/01. executable/gnt.bat\", \"$(dbin)gnt.bat\", true)]"
        ]
      }
    }
  ]
}