<commit_before>param(
   [Parameter(Mandatory=$true, Position=0)][string]$ProjectName,
   [Parameter(Mandatory=$true)][Version]$AssemblyVersion,
   [Parameter(Mandatory=$true)][Version]$PackageVersion,
   [Parameter()][string]$PreRelease
)

$ErrorActionPreference = "Stop"
Push-Location (Split-Path $script:MyInvocation.MyCommand.Path)

$solutionPath = Resolve-Path ..\..
$nuget = Join-Path $solutionPath .nuget\nuget.exe

function script:DownloadNuGet {
   ../ensure-nuget.ps1
}

function script:RestorePackages {
   &$nuget restore $solutionPath\DbExtensions.sln
}

function script:NuSpec {

   $targetFx = $projDoc.DocumentElement.SelectSingleNode("*/*[local-name() = 'TargetFrameworkVersion']").InnerText
   $targetFxMoniker = "net" + $targetFx.Substring(1).Replace(".", "")

   "<package xmlns='http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd'>"
      "<metadata>"
         "<id>$projName</id>"
         "<version>$pkgVersion</version>"
         "<authors>$($notice.authors)</authors>"
         "<licenseUrl>$($notice.license.url)</licenseUrl>"
         "<projectUrl>$($notice.website)</projectUrl>"
         "<iconUrl>$($notice.website)nuget/icon.png</iconUrl>"
         "<releaseNotes>For a list of changes see $($notice.website)docs/changes.html</releaseNotes>"

   if ($projName -eq "DbExtensions") {

      "<description>DbExtensions is a data-access framework with a strong focus on query composition, granularity and code aesthetics. It supports both POCO and dynamic (untyped) mapping.</description>"
      "<copyright>$($notice.copyright)</copyright>"
      "<tags>ado.net orm micro-orm</tags>"

      "<frameworkAssemblies>"
         "<frameworkAssembly assemblyName='System.Core'/>"
         "<frameworkAssembly assemblyName='System.Data'/>"
      "</frameworkAssemblies>"
   }

   "</metadata>"

   "<files>"
      "<file src='$solutionPath\LICENSE.txt'/>"
      "<file src='$solutionPath\NOTICE.xml'/>"
      "<file src='$projPath\bin\Release\$projName.dll' target='lib\$targetFxMoniker'/>"
      "<file src='$projPath\bin\Release\$projName.pdb' target='lib\$targetFxMoniker'/>"
      "<file src='$solutionPath\build\docs\api\xml\$projName.xml' target='lib\$targetFxMoniker'/>"
   "</files>"

   "</package>"
}

function script:NuPack([string]$projName) {

   $projPath = Resolve-Path $solutionPath\src\$projName
   $projFile = "$projPath\$projName.csproj"

   if (-not (Test-Path temp -PathType Container)) {
      md temp | Out-Null
   }

   if (-not (Test-Path temp\$projName -PathType Container)) {
      md temp\$projName | Out-Null
   }

   if (-not (Test-Path nupkg -PathType Container)) {
      md nupkg | Out-Null
   }

   $tempPath = Resolve-Path temp\$projName
   $outputPath = Resolve-Path nupkg

   ## Read project file

   $projDoc = New-Object Xml.XmlDocument
   $projDoc.PreserveWhitespace = $true
   $projDoc.Load($projFile)

   ## Create nuspec using info from project file and notice

   [xml]$noticeDoc = Get-Content $solutionPath\NOTICE.xml
   $notice = $noticeDoc.DocumentElement

   $pkgVersion = "$PackageVersion$(if ($PreRelease) { ""-$PreRelease"" } else { $null })"
   $nuspecPath = "$tempPath\$projName.nuspec"

   NuSpec | Out-File $nuspecPath -Encoding utf8

   ## Create assembly signature file

   $signaturePath = "$tempPath\AssemblySignature.cs"
   $signature = @"
using System;
using System.Reflection;

[assembly: AssemblyProduct("DbExtensions")]
[assembly: AssemblyCompany("$projectUrl")]
[assembly: AssemblyCopyright("$copyright")]
[assembly: AssemblyVersion("$AssemblyVersion")]
[assembly: AssemblyFileVersion("$PackageVersion")]
[assembly: AssemblyInformationalVersion("$pkgVersion")]<commit_msg>release script fix<commit_after>param(
   [Parameter(Mandatory=$true, Position=0)][string]$ProjectName,
   [Parameter(Mandatory=$true)][Version]$AssemblyVersion,
   [Parameter(Mandatory=$true)][Version]$PackageVersion,
   [Parameter()][string]$PreRelease
)

$ErrorActionPreference = "Stop"
Push-Location (Split-Path $script:MyInvocation.MyCommand.Path)

$solutionPath = Resolve-Path ..\..
$nuget = Join-Path $solutionPath .nuget\nuget.exe

function script:DownloadNuGet {
   ../ensure-nuget.ps1
}

function script:RestorePackages {
   &$nuget restore $solutionPath\DbExtensions.sln
}

function script:NuSpec {

   $targetFx = $projDoc.DocumentElement.SelectSingleNode("*/*[local-name() = 'TargetFrameworkVersion']").InnerText
   $targetFxMoniker = "net" + $targetFx.Substring(1).Replace(".", "")

   "<package xmlns='http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd'>"
      "<metadata>"
         "<id>$projName</id>"
         "<version>$pkgVersion</version>"
         "<authors>$($notice.authors)</authors>"
         "<licenseUrl>$($notice.license.url)</licenseUrl>"
         "<projectUrl>$($notice.website)</projectUrl>"
         "<iconUrl>$($notice.website)nuget/icon.png</iconUrl>"
         "<releaseNotes>For a list of changes see $($notice.website)docs/changes.html</releaseNotes>"

   if ($projName -eq "DbExtensions") {

      "<description>DbExtensions is a data-access framework with a strong focus on query composition, granularity and code aesthetics. It supports both POCO and dynamic (untyped) mapping.</description>"
      "<copyright>$($notice.copyright)</copyright>"
      "<tags>ado.net orm micro-orm</tags>"

      "<frameworkAssemblies>"
         "<frameworkAssembly assemblyName='System.Core'/>"
         "<frameworkAssembly assemblyName='System.Data'/>"
      "</frameworkAssemblies>"
   }

   "</metadata>"

   "<files>"
      "<file src='$solutionPath\LICENSE.txt'/>"
      "<file src='$solutionPath\NOTICE.xml'/>"
      "<file src='$projPath\bin\Release\$projName.dll' target='lib\$targetFxMoniker'/>"
      "<file src='$projPath\bin\Release\$projName.pdb' target='lib\$targetFxMoniker'/>"
      "<file src='$solutionPath\build\docs\api\xml\$projName.xml' target='lib\$targetFxMoniker'/>"
   "</files>"

   "</package>"
}

function script:NuPack([string]$projName) {

   $projPath = Resolve-Path $solutionPath\src\$projName
   $projFile = "$projPath\$projName.csproj"

   if (-not (Test-Path temp -PathType Container)) {
      md temp | Out-Null
   }

   if (-not (Test-Path temp\$projName -PathType Container)) {
      md temp\$projName | Out-Null
   }

   if (-not (Test-Path nupkg -PathType Container)) {
      md nupkg | Out-Null
   }

   $tempPath = Resolve-Path temp\$projName
   $outputPath = Resolve-Path nupkg

   ## Read project file

   $projDoc = New-Object Xml.XmlDocument
   $projDoc.PreserveWhitespace = $true
   $projDoc.Load($projFile)

   ## Create nuspec using info from project file and notice

   [xml]$noticeDoc = Get-Content $solutionPath\NOTICE.xml
   $notice = $noticeDoc.DocumentElement

   $pkgVersion = "$PackageVersion$(if ($PreRelease) { ""-$PreRelease"" } else { $null })"
   $nuspecPath = "$tempPath\$projName.nuspec"

   NuSpec | Out-File $nuspecPath -Encoding utf8

   ## Create assembly signature file

   $signaturePath = "$tempPath\AssemblySignature.cs"
   $signature = @"
using System;
using System.Reflection;

[assembly: AssemblyProduct("$($notice.work)")]
[assembly: AssemblyCompany("$($notice.website)")]
[assembly: AssemblyCopyright("$($notice.copyright)")]
[assembly: AssemblyVersion("$AssemblyVersion")]
[assembly: AssemblyFileVersion("$PackageVersion")]
[assembly: AssemblyInformationalVersion("$pkgVersion")]
{'fraction_non_alphanumeric': 0.16306269549843602, 'fraction_numerical': 0.0027199782401740786, 'mean_word_length': 4.267908309455588, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2185889', 'n_tokens_mistral': 2429, 'n_tokens_neox': 2273, 'n_words': 407}