Last active
January 6, 2020 15:01
-
-
Save GeorgDangl/86ea4cacaefaf5d74f10afbfcfbc5be0 to your computer and use it in GitHub Desktop.
Deploying Asp.Net Core Applications from Jenkins to IIS or Azure via WebDeploy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk.Web"> | |
<ItemGroup> | |
<PackageReference Include="WebConfigTransformRunner" Version="1.0.0.1"> | |
<PrivateAssets>All</PrivateAssets> | |
</PackageReference> | |
</ItemGroup> | |
<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish"> | |
<Exec Command="npm install" /> | |
<Exec Command="bower install" /> | |
<Exec Command="gulp clean" /> | |
<Exec Command="gulp min" /> | |
</Target> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$environmentName = "Production" | |
# Applying web.config transformations | |
$webConfigTransformatorPackages = Join-Path -Path $env:USERPROFILE -ChildPath "\.nuget\packages\WebConfigTransformRunner" | |
$latestWebConfigTranformator = Join-Path -Path ((Get-ChildItem -Path $webConfigTransformatorPackages | Sort-Object Fullname -Descending)[0].FullName) -ChildPath "Tools\WebConfigTransformRunner.exe" | |
$webConfigDirs = Get-ChildItem -Path "$PSScriptRoot\publish" -Recurse -Filter "web*.config" | Select -Property Directory -Unique | |
ForEach ($directory in $webConfigDirs.Directory){ | |
$transformationSource = (Get-ChildItem -Path $directory -Filter ("web." + $environmentName + ".config")) | |
if ($transformationSource) { | |
$guid = [Guid]::NewGuid().ToString() | |
$transformArguments = @("""" + (Join-Path -Path $directory -ChildPath "web.config") + """",` | |
"""" + $transformationSource[0].FullName + """",` | |
"""" + (Join-Path -Path $directory -ChildPath $guid) + """") | |
$transformationProcess = Start-Process -FilePath $latestWebConfigTranformator -ArgumentList $transformArguments -Wait -PassThru -NoNewWindow | |
# Delete original web.config and rename the created one | |
Remove-Item -Path (Join-Path -Path $directory -ChildPath "web.config") | |
Rename-Item -Path (Join-Path -Path $directory -ChildPath $guid) -NewName (Join-Path -Path $directory -ChildPath "web.config") | |
} | |
# Delete all web.*.config files | |
ForEach ($file in (Get-ChildItem -Path $directory -Filter "web.*.config")){ | |
Write-Host "Removing $file" | |
Remove-Item -Path $file.FullName | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment