<commit_before># EXIT CODES
# 1: dotnet packaging failure
# 2: dotnet publishing failure
# 3: Unit test failure
# 4: dotnet / NuGet package restore failure

<#
 .SYNOPSIS
  Gets the set of directories in which projects are available for compile/processing.

 .PARAMETER RootPath
  Path where searching for project directories should begin.
#>
function Get-DotNetProjectDirectory
{
  [CmdletBinding()]
  Param(
    [Parameter(Mandatory=$True, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$False)]
    [ValidateNotNullOrEmpty()]
    [string]
    $RootPath
  )

  # We don't search for project.json because that gets copied around. .csproj is the only
  # good way to actually locate where the source project is.
  Get-ChildItem -Path $RootPath -Recurse -Include "*.csproj" | Select-Object @{ Name="ParentFolder"; Expression={ $_.Directory.FullName.TrimEnd("\") } } | Select-Object -ExpandProperty ParentFolder
}

<#
 .SYNOPSIS
  Runs the dotnet CLI RC2 install script from GitHub to install a project-local
  copy of the CLI.
#>
function Install-DotNetCli
{
  $callerPath = Split-Path $MyInvocation.PSCommandPath
  $env:DOTNET_INSTALL_DIR = Join-Path -Path $callerPath -ChildPath ".dotnet\cli"
  if (!(Test-Path $env:DOTNET_INSTALL_DIR))
  {
    New-Item -ItemType Directory -Path "$($env:DOTNET_INSTALL_DIR)" | Out-Null
  }

  # Download the dotnet CLI install script
  if (!(Test-Path .\dotnet\install.ps1))
  {
    Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.ps1" -OutFile ".\.dotnet\dotnet-install.ps1"
  }

  # Run the dotnet CLI install
  & .\.dotnet\dotnet-install.ps1

  # Add the dotnet folder path to the process.
  Remove-EnvironmentPathEntry $env:DOTNET_INSTALL_DIR
  $env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH"
}

<#
.SYNOPSIS
    Builds a project using dotnet cli.
.DESCRIPTION
    Builds a project in a specified directory using the dotnet cli.
.PARAMETER DirectoryName
    The path to the directory containing the project to build.
#>
function Invoke-DotNetBuild
{
  [CmdletBinding()]
  Param(
    [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
    [ValidateNotNull()]
    [System.IO.DirectoryInfo[]]
    $ProjectDirectory
  )
  Process
  {
    foreach($Project in $ProjectDirectory)
    {
      & dotnet build ("""" + $Project.FullName + """") --configuration Release
      if($LASTEXITCODE -ne 0)
      {
        exit 1
      }
    }
  }
}

<#
 .SYNOPSIS
  Invokes the dotnet utility to package a project.

 .PARAMETER ProjectDirectory
  Path to the directory containing the project to package.

 .PARAMETER PackagesPath
  Path to the "artifacts\packages" folder where packages should go.
#>
function Invoke-DotNetPack
{
  [CmdletBinding()]
  Param(
    [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
    [ValidateNotNull()]
    [System.IO.DirectoryInfo[]]
    $ProjectDirectory,

    [Parameter(Mandatory=$True, ValueFromPipeline=$False)]
    [ValidateNotNull()]
    [System.IO.DirectoryInfo]
    $PackagesPath
  )
  Begin
  {
    New-Item -Path $PackagesPath -ItemType Directory -Force | Out-Null
  }
  Process
  {
    foreach($Project in $ProjectDirectory)
    {
      & dotnet build ("""" + $Project.FullName + """") --configuration Release
      & dotnet pack ("""" + $Project.FullName + """") --configuration Release --output $PackagesPath
      if($LASTEXITCODE -ne 0)
      {
        exit 1
      }
    }
  }
}

<#
 .Synopsis
  Invokes dotnet test command.

 .Parameter ProjectDirectory
  Path to the directory containing the project to package.
#>
function Invoke-Test
{
  [CmdletBinding()]
  Param(
    [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
    [ValidateNotNull()]
    [System.IO.DirectoryInfo[]]
    $ProjectDirectory
  )
  Process
  {
    foreach($Project in $ProjectDirectory)
    {
      & dotnet test ("""" + $Project.FullName + """")
      if($LASTEXITCODE -ne 0)
      {
        exit 3
      }
    }
  }
}

<#
.SYNOPSIS
    Removes a path entry from the current user and process path.
.DESCRIPTION
    Updates the user and process paths as needed to remove a specific path
    from the overall search path.
.PARAMETER VariableToRemove
    The directory/path that should be removed.
#>
function Remove-EnvironmentPathEntry
{
  [cmdletbinding()]
  param([string] $VariableToRemove)
  $path = [Environment]::GetEnvironmentVariable("PATH", "User")
  $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove }
  [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
  $path = [Environment]::GetEnvironmentVariable("PATH", "Process")
  $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove }
  [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
}

<#
 .SYNOPSIS
  Restores dependencies using the dotnet utility.

 .PARAMETER ProjectDirectory
  Path to the directory containing the project with dependencies to restore.
#>
function Restore-DependencyPackages
{
  [CmdletBinding()]
  Param(
    [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
    [ValidateNotNull()]
    [System.IO.DirectoryInfo[]]
    $ProjectDirectory
  )
  Process
  {
    foreach($Project in $ProjectDirectory)
    {
      & dotnet restore ("""" + $Project.FullName + """") --no-cache
      if($LASTEXITCODE -ne 0)
      {
        exit 4
      }
    }
  }
}
<commit_msg>Updated Autofac.Build.psm1 dotnet-cli download path.<commit_after># EXIT CODES
# 1: dotnet packaging failure
# 2: dotnet publishing failure
# 3: Unit test failure
# 4: dotnet / NuGet package restore failure

<#
 .SYNOPSIS
  Gets the set of directories in which projects are available for compile/processing.

 .PARAMETER RootPath
  Path where searching for project directories should begin.
#>
function Get-DotNetProjectDirectory
{
  [CmdletBinding()]
  Param(
    [Parameter(Mandatory=$True, ValueFromPipeline=$False, ValueFromPipelineByPropertyName=$False)]
    [ValidateNotNullOrEmpty()]
    [string]
    $RootPath
  )

  # We don't search for project.json because that gets copied around. .csproj is the only
  # good way to actually locate where the source project is.
  Get-ChildItem -Path $RootPath -Recurse -Include "*.csproj" | Select-Object @{ Name="ParentFolder"; Expression={ $_.Directory.FullName.TrimEnd("\") } } | Select-Object -ExpandProperty ParentFolder
}

<#
 .SYNOPSIS
  Runs the dotnet CLI RC2 install script from GitHub to install a project-local
  copy of the CLI.
#>
function Install-DotNetCli
{
  $callerPath = Split-Path $MyInvocation.PSCommandPath
  $env:DOTNET_INSTALL_DIR = Join-Path -Path $callerPath -ChildPath ".dotnet\cli"
  if (!(Test-Path $env:DOTNET_INSTALL_DIR))
  {
    New-Item -ItemType Directory -Path "$($env:DOTNET_INSTALL_DIR)" | Out-Null
  }

  # Download the dotnet CLI install script
  if (!(Test-Path .\dotnet\install.ps1))
  {
    Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile ".\.dotnet\dotnet-install.ps1"
  }

  # Run the dotnet CLI install
  & .\.dotnet\dotnet-install.ps1

  # Add the dotnet folder path to the process.
  Remove-EnvironmentPathEntry $env:DOTNET_INSTALL_DIR
  $env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH"
}

<#
.SYNOPSIS
    Builds a project using dotnet cli.
.DESCRIPTION
    Builds a project in a specified directory using the dotnet cli.
.PARAMETER DirectoryName
    The path to the directory containing the project to build.
#>
function Invoke-DotNetBuild
{
  [CmdletBinding()]
  Param(
    [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
    [ValidateNotNull()]
    [System.IO.DirectoryInfo[]]
    $ProjectDirectory
  )
  Process
  {
    foreach($Project in $ProjectDirectory)
    {
      & dotnet build ("""" + $Project.FullName + """") --configuration Release
      if($LASTEXITCODE -ne 0)
      {
        exit 1
      }
    }
  }
}

<#
 .SYNOPSIS
  Invokes the dotnet utility to package a project.

 .PARAMETER ProjectDirectory
  Path to the directory containing the project to package.

 .PARAMETER PackagesPath
  Path to the "artifacts\packages" folder where packages should go.
#>
function Invoke-DotNetPack
{
  [CmdletBinding()]
  Param(
    [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
    [ValidateNotNull()]
    [System.IO.DirectoryInfo[]]
    $ProjectDirectory,

    [Parameter(Mandatory=$True, ValueFromPipeline=$False)]
    [ValidateNotNull()]
    [System.IO.DirectoryInfo]
    $PackagesPath
  )
  Begin
  {
    New-Item -Path $PackagesPath -ItemType Directory -Force | Out-Null
  }
  Process
  {
    foreach($Project in $ProjectDirectory)
    {
      & dotnet build ("""" + $Project.FullName + """") --configuration Release
      & dotnet pack ("""" + $Project.FullName + """") --configuration Release --output $PackagesPath
      if($LASTEXITCODE -ne 0)
      {
        exit 1
      }
    }
  }
}

<#
 .Synopsis
  Invokes dotnet test command.

 .Parameter ProjectDirectory
  Path to the directory containing the project to package.
#>
function Invoke-Test
{
  [CmdletBinding()]
  Param(
    [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
    [ValidateNotNull()]
    [System.IO.DirectoryInfo[]]
    $ProjectDirectory
  )
  Process
  {
    foreach($Project in $ProjectDirectory)
    {
      & dotnet test ("""" + $Project.FullName + """")
      if($LASTEXITCODE -ne 0)
      {
        exit 3
      }
    }
  }
}

<#
.SYNOPSIS
    Removes a path entry from the current user and process path.
.DESCRIPTION
    Updates the user and process paths as needed to remove a specific path
    from the overall search path.
.PARAMETER VariableToRemove
    The directory/path that should be removed.
#>
function Remove-EnvironmentPathEntry
{
  [cmdletbinding()]
  param([string] $VariableToRemove)
  $path = [Environment]::GetEnvironmentVariable("PATH", "User")
  $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove }
  [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "User")
  $path = [Environment]::GetEnvironmentVariable("PATH", "Process")
  $newItems = $path.Split(';') | Where-Object { $_.ToString() -inotlike $VariableToRemove }
  [Environment]::SetEnvironmentVariable("PATH", [System.String]::Join(';', $newItems), "Process")
}

<#
 .SYNOPSIS
  Restores dependencies using the dotnet utility.

 .PARAMETER ProjectDirectory
  Path to the directory containing the project with dependencies to restore.
#>
function Restore-DependencyPackages
{
  [CmdletBinding()]
  Param(
    [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
    [ValidateNotNull()]
    [System.IO.DirectoryInfo[]]
    $ProjectDirectory
  )
  Process
  {
    foreach($Project in $ProjectDirectory)
    {
      & dotnet restore ("""" + $Project.FullName + """") --no-cache
      if($LASTEXITCODE -ne 0)
      {
        exit 4
      }
    }
  }
}

{'fraction_non_alphanumeric': 0.1206448723690103, 'fraction_numerical': 0.0035826242722794446, 'mean_word_length': 3.6876574307304786, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3273281', 'n_tokens_mistral': 3498, 'n_tokens_neox': 3467, 'n_words': 886}