PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Nuget.ps1

https://bitbucket.org/raptux/sharpmt940lib
Powershell | 175 lines | 119 code | 51 blank | 5 comment | 8 complexity | 4333b29c5d62e01203e12c08e0c9ac8a MD5 | raw file
  1. $path = pwd
  2. $path = $path.Path
  3. Function BuildSolution ([string]$configuration, [string]$platform) {
  4. $buildlog = ".artifacts\msbuild_$platform.txt".
  5. ToLower().
  6. Replace(" ","")
  7. Write-Host -NoNewLine "Building ($platform | $configuration) using log: $buildlog."
  8. $result = Start-Process `
  9. -FilePath msbuild `
  10. -PassThru `
  11. -Wait `
  12. -RedirectStandardOutput $buildlog `
  13. -NoNewWindow `
  14. -ArgumentList `
  15. @("/m",
  16. "/target:`"Raptorious_SharpMt940Lib:Rebuild`"",
  17. "/property:Platform=`"$platform`"",
  18. "/property:Configuration=`"$configuration`"",
  19. "/property:OutputPath=`"..\.artifacts\$platform\lib\net40-client`"",
  20. "/property:msbuildemitsolution=1"
  21. "/nologo",
  22. "Raptorious.SharpMT940Lib.sln")
  23. if ($result.ExitCode -ne 0) {
  24. Write-Host -ForegroundColor Red " Failed, errors"
  25. Get-Content $buildlog
  26. }
  27. else {
  28. Write-Host -ForegroundColor Green " Done, no errors"
  29. }
  30. Write-Host
  31. return $result
  32. }
  33. Function GetMsBuildPath([string]$version) {
  34. return (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\$version" MSBuildToolsPath).MSBuildToolsPath
  35. }
  36. Function CreateXmlWriter($path) {
  37. # get an XMLTextWriter to create the XML
  38. $XmlWriter = New-Object System.XMl.XmlTextWriter($path,$Null)
  39. # choose a pretty formatting:
  40. $xmlWriter.Formatting = 'Indented'
  41. $xmlWriter.Indentation = 1
  42. $XmlWriter.IndentChar = "`t"
  43. $xmlWriter.WriteStartDocument()
  44. return $xmlWriter
  45. }
  46. Function GetNuspecInfo([string]$platform) {
  47. Write-Host -NoNewline "Colllecting nuget information..."
  48. $versionInfo = (dir .\.artifacts\$platform\lib\net40-client\Raptorious.SharpMt940Lib.dll).VersionInfo
  49. $changlog = Get-Content "$path\Raptorious.SharpMT940Lib\CHANGELOG.md"
  50. $nuget = @{
  51. "id" = "Raptorious.Finance.Swift.Mt940"
  52. "title" = "SharpMt940Lib"
  53. "authors" = "Jaco Adriaansen"
  54. "licenseUrl" = "http://www.raptorious.com/mt940lib/"
  55. "projectUrl" = "http://www.raptorious.com/mt940lib/"
  56. "requireLicenseAcceptance" = "false"
  57. "copyright" = "Copyright 2012-2014"
  58. "version" = $versionInfo.ProductVersion
  59. "description" = $versionInfo.Comments
  60. "tags" = "finance mt940 bank"
  61. "releaseNotes" = $changelog
  62. }
  63. Write-Host -ForegroundColor Yellow " Found" $nuget.Title.ToString() "version" $nuget.Version.ToString()
  64. return $nuget
  65. }
  66. Function GenerateNuspec($nuget, [string]$output) {
  67. Write-Host -NoNewline "Creating nuspec: $output"
  68. $writer = CreateXmlWriter($output)
  69. $writer.WriteStartElement("package")
  70. $writer.WriteStartElement("metadata")
  71. foreach($item in $nuget.Keys) {
  72. $writer.WriteElementString($item, $nuget[$item])
  73. }
  74. #$writer.WriteStartElement("files")
  75. #$writer.WriteElementString("file", "README.md")
  76. #$writer.WriteEndElement()
  77. $writer.WriteStartElement("references")
  78. $writer.WriteStartElement("reference")
  79. $writer.WriteAttributeString("file", "Raptorious.SharpMt940Lib.dll")
  80. $writer.WriteEndElement()
  81. $writer.WriteEndElement()
  82. $writer.WriteEndElement()
  83. $writer.WriteEndElement()
  84. $writer.WriteEndDocument()
  85. $writer.Flush()
  86. $writer.Close()
  87. Write-Host -ForegroundColor Yellow " Done."
  88. }
  89. Function PreparePackage([string]$platform) {
  90. }
  91. $msbuild_path = GetMsBuildPath("4.0")
  92. $env:Path += ";" + $msbuild_path
  93. $default = "Any CPU"
  94. $platforms = @("Any CPU", "x86", "x64")
  95. $configuration = "Release"
  96. $results = @()
  97. $push = Read-Host 'Push to nuget.org? [y/N]'
  98. foreach($platform in $platforms) {
  99. $results += BuildSolution $configuration $platform
  100. $nuget = GetNuspecInfo $platform
  101. $output = $path + "\.artifacts\$platform\Raptorious.SharpMt940LibSwift"
  102. if($platform -ne "Any CPU") {
  103. $output += ".$platform"
  104. $nuget.Set_Item("id", $nuget.Id + ".$platform")
  105. $nuget.Set_Item("title", $nuget.Title.ToString() + "($platform)")
  106. }
  107. $output += ".nuspec"
  108. GenerateNuspec $nuget $output
  109. $nuget_exec = $path + "\.nuget\nuget.exe"
  110. cd "$path\.artifacts\$platform"
  111. $result = Invoke-Expression "$nuget_exec pack -Symbols `"$output`""
  112. if($push.ToLower() -eq 'y') {
  113. foreach($i in 1..2) {
  114. $nuget_package = $result[$i].Substring("Successfully created package ".Length).Trim(".")
  115. Write-Host $nuget_package
  116. Invoke-Expression "$nuget_exec push $nuget_package"
  117. }
  118. }
  119. cd $path
  120. Write-Host
  121. Write-Host -ForegroundColor Green "Done."
  122. Write-Host
  123. }
  124. pause