Skip to content

Instantly share code, notes, and snippets.

@jrotello
Last active October 13, 2017 21:56
Show Gist options
  • Save jrotello/2d23619c17ad7f1d385569bd6ad5ccea to your computer and use it in GitHub Desktop.
Save jrotello/2d23619c17ad7f1d385569bd6ad5ccea to your computer and use it in GitHub Desktop.
Script to mark '*.Tests.csproj' as C# test projects.
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$BasePath
)
Push-Location $BasePath
$Namespace = 'http://schemas.microsoft.com/developer/msbuild/2003'
$ProjectTypeGuids = '{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}' # TestProject;C#
$TestProjectType= 'UnitTest'
Get-ChildItem .\ -Include *.Tests.csproj -Recurse |
ForEach-Object {
Write-Host "Processing $($_.FullName)..." -ForegroundColor DarkYellow
$xml = [xml](Get-Content $_)
$propertygroup = $xml.Project.PropertyGroup[0]
if (-not $propertygroup.ProjectTypeGuids) {
Write-Host "`t* ProjectTypeGuids element not found... Creating" -ForegroundColor DarkCyan
$element = $xml.CreateElement('ProjectTypeGuids', $Namespace)
$element.InnerText = $ProjectTypeGuids
$propertygroup.AppendChild($element) | Out-Null
}
if (-not $propertygroup.TestProjectType) {
Write-Host "`t* TestProjectType element not found... Creating" -ForegroundColor DarkCyan
$element = $xml.CreateElement('TestProjectType', $Namespace)
$element.InnerText = $TestProjectType
$propertygroup.AppendChild($element) | Out-Null
}
$xml.Save($_)
}
Pop-Location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment