GJaminon
6/25/2018 - 11:18 AM

ASPNetCore Build in Powershell

param(
   [string]$AppName ,
   [string]$artifactPath = "E:\Artifacts" 
  
)



Get-ChildItem -Recurse -Hidden -Path .



$nuspec = @"
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <id>__appName__</id>
    <version>__appVersion__</version>
    <title>__appName__</title>
    <authors>Gaetan Jaminon</authors>
    <owners>Gaetan Jaminon</owners>
    <licenseUrl>http://www.wtfpl.net/</licenseUrl>
    <projectUrl>http://www.asp.net</projectUrl>
    <iconUrl>http://proget.aesondev.cloud/endpoints/Logo/content/asp-net-core-logo.png</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description> DevOps Demo app</description>
    <summary>Devops Demo App</summary>
    <releaseNotes></releaseNotes>
    <tags>DevOps</tags>
    <packageSourceUrl>http://proget.aesondev.cloud</packageSourceUrl>
    <docsUrl>http://proget.aesondev.cloud</docsUrl>   
  </metadata>
</package>
"@

Write-Output "Getting Version with GitVersion ..."

$version = gitversion | ConvertFrom-Json
$versionName = $version.FullSemVer.Replace('+','.')
Write-Output $version


Write-Output "Set version $versionName for $AppName in nuspec"
$nuspec = $nuspec.Replace('__appName__',$AppName)
$nuspec = $nuspec.Replace('__appVersion__',$versionName)



$appArtifactPath = "$artifactPath\$AppName\$versionName"
Write-Output "Creating artifacts folder $appArtifactPath" 
New-Item -ItemType Directory -Path $appArtifactPath -Force


$publishPath = "$appArtifactPath\source\"
Write-Output "Creating publish folder $publishPath "
New-Item -ItemType Directory -Path $publishPath -Force

Set-Location "./$AppName"

Get-Location


dotnet restore 



dotnet build /p:Major="$version.Major" /p:Minor"$version.Minor" /p:patch="$version.Patch" /p:buildnumber="$version.BuildMetaDataPadded" 

dotnet publish --output "$publishPath" --no-restore --no-build 



$nuspecPath = "$appArtifactPath\$AppName.nuspec"
Write-Output "Generating the .nuspec file $nuspecPath"
New-Item -Path $nuspecPath  -Force
Set-Content $nuspecPath -Value $nuspec -Force


Write-Output "Genrating the choco package in $appArtifactPath "
Set-Location $appArtifactPath
choco pack


$chocoFeed = "http://proget.aesondev.cloud/nuget/Applications/"
Write-Output "Pushig the packahe to $chocoFeed"
choco push --source=$chocoFeed --api-key=Admin:Admin --force


Pop-Location