Created
September 27, 2019 17:12
-
-
Save johnmmoss/2aae62214aa8bd3d84b653c22c7c9a78 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Add-WebTransform -ProjectPath "WebApplication1.csproj" -Environment "Dev" | |
Add-WebTransform -ProjectPath "WebApplication1.csproj" -Environment "Live" | |
Add-WebTransform -ProjectPath "WebApplication1.csproj" -Environment "PreLive" | |
Add-WebTransform -ProjectPath "WebApplication1.csproj" -Environment "Staging" | |
function Add-WebTransform() { | |
Param( | |
$ProjectPath = "WebApplication1.csproj", | |
$Environment = "Dev" | |
) | |
# TODO Add some param guards | |
$webTransformFile = ".\Web.$Environment.config" | |
if ( -not (Test-Path $webTransformFile )) | |
{ | |
$content = | |
'<?xml version="1.0" encoding="utf-8" ?> | |
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> | |
</configuration>' | |
$content | out-file -FilePath $webTransformFile | |
} | |
$csprojFile = get-content -path $ProjectPath | |
if ($csprojFile -notmatch "^.*<Content.*Web\.Dev\.config.*$") | |
{ | |
$csprojIncludeWebConfig = '<Content Include="Web.config" />' | |
$csprojIncludeTransform = "`t<Content Include=`"Web.$Environment.config`">`n`t`t<DependentUpon>Web.config</DependentUpon>`n`t</Content>" | |
$csprojFileUpdated = $csprojFile -replace $csprojIncludeWebConfig, "$csprojIncludeWebConfig`n $csprojIncludeTransform" | |
set-content -Path $ProjectPath -Value $csprojFileUpdated | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment