Advertisement
Guest User

TFS Build Powershell Script for .NET Core Deployment

a guest
Oct 10th, 2016
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. param (
  2.     [Parameter(Mandatory=$true)][string]$OutputDir
  3.  )
  4.  
  5. # First run dotnet restore for each of the projects
  6. # We need this because dotnet publish does not restore dependencies on referenced projects
  7. Get-ChildItem |
  8. Foreach-Object {
  9.     Write-Output "============================="
  10.     Write-Output $_.Name
  11.     Write-Output "============================="
  12.  
  13.     Write-Output "Running dotnet restore for project: " + $_.Name;
  14.     $Command = "dotnet restore """ + $_.FullName + "\project.json"""
  15.     Write-Output $Command
  16.     iex $Command
  17. }
  18.  
  19. # Now that all dependencies are restored, run dotnet publish to the output dir
  20. Get-ChildItem |
  21. Foreach-Object {
  22.     Write-Output "============================="
  23.     Write-Output $_.Name
  24.     Write-Output "============================="
  25.  
  26.     $OutputFolder = $OutputDir + "\" + $_.Name
  27.     $FolderExists = Test-Path($OutputFolder)
  28.     if ($FolderExists -eq $False)
  29.     {
  30.         New-Item $OutputFolder -type directory
  31.         Write-Output "Create Output folder: " + $OutputFolder;
  32.     }
  33.  
  34.     # Need to remove read only attribute since TFS get will set the readonly attribute
  35.     $Command = "attrib -r """ + $_.FullName + "\*.*"" /S";
  36.     Write-Output $Command
  37.     iex $Command
  38.  
  39.     $Command = "attrib -r """ + $OutputFolder + "\*.*"" /S";
  40.     Write-Output $Command
  41.     iex $Command
  42.  
  43.     Write-Output "Publishing " + $_.Name;
  44.     $Command = "dotnet publish """ + $_.FullName + "\project.json"" -o """ + $OutputFolder + """ -c Release"
  45.     Write-Output $Command
  46.     iex $Command
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement