# From http://rafdelgado.blogspot.com/2012/06/powershell-removing-special-characters.html
Function Convert-ToFriendlyName
{
param ($Text)
# Unwanted characters (includes spaces and '-') converted to a regex:
$SpecChars = '!', '"', '£', '$', '%', '&', '^', '*', '(', ')', '@', '=', '+', '¬', '`', '\', '<', '>', '.', '?', '/', ':', ';', '#', '~', "'", '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', ' '
$remspecchars = [string]::join('|', ($SpecChars | % {[regex]::escape($_)}))
# Convert the text given to correct naming format (Uppercase)
$name = (Get-Culture).textinfo.totitlecase(“$Text”.tolower())
# Remove unwanted characters
$name = $name -replace $remspecchars, ""
$name
}
function SplitFixtureFile
{
param([string]$filepath,[string]$deployDestination)
if (Test-Path $filepath -PathType Leaf) {
$reader = new-object System.IO.StreamReader($filepath)
$filename = "NUL"
if(!(Test-Path -Path $deployDestination )){
New-Item -ItemType directory -Path $TARGETDIR
}
while(($line = $reader.ReadLine()) -ne $null)
{
if ($line.ToLower().StartsWith("fixture:") || )
{
$line -imatch "fixture: (?<content>.*)"
$fixture_name = Convert-ToFriendlyName $matches['content']
$filename = "{0}\{1}.fixture" -f ($deployDestination, $fixture_name)
}
Add-Content -path $fileName -value $line
}
$reader.Close()
}
}
SplitFixtureFile $args[0] $args[1]
<Target Name="SplitFixtureFile" Condition=" '$(WriteLogEntry)'!='false' ">
<PropertyGroup>
<PowerShellExe Condition=" '$(PowerShellExe)'=='' ">
%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
</PowerShellExe>
<ScriptLocation Condition=" '$(ScriptLocation)'=='' ">
$(MSBuildProjectDirectory)\SplitFixtureFile.ps1
</ScriptLocation>
<FixtureFileOutputPath Condition=" '$(FixtureFileOutputPath)'=='' ">
$(MSBuildProjectDirectory)\Fixtures
</FixtureFileOutputPath>
</PropertyGroup>
<Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted
-command "& {
&'$(ScriptLocation)'
'$(FixtureFileOutputPath)' } ""
/>
</Target>