Skip to content

Instantly share code, notes, and snippets.

@Haemoglobin
Created March 26, 2012 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Haemoglobin/2205505 to your computer and use it in GitHub Desktop.
Save Haemoglobin/2205505 to your computer and use it in GitHub Desktop.
Add Source File Headers
#requires -version 2
<# #>
param(
[Parameter(Mandatory = $true)]
[string] $sourceRoot,
[Parameter(Mandatory = $true)]
[string] $versionNumber
)
function CorrectPathBackslash {
param([string] $path)
if (![String]::IsNullOrEmpty($path)) {
if (!$path.EndsWith("\")) {
$path += "\"
}
}
return $path
}
$sourceRoot = CorrectPathBackslash $sourceRoot
#Change any ..\.. etc to proper path for path length usage later
$sourceRoot = [IO.Path]::GetFullPath($sourceRoot)
$today = Get-Date -format g
$visitedFiles = @{}
$projects = Get-ChildItem $sourceRoot -Filter *.csproj -Recurse
foreach($project in $projects) {
Write-Verbose "Processing $($project.Name)..."
$projectXml = New-Object XML
$projectXml.Load($project.FullName)
if ($projectXml.Project.PropertyGroup.Length -lt 1) {
Write-Verbose "No default property group for $($project.FullName)"
continue
}
$assemblyName = $projectXml.Project.PropertyGroup[0].AssemblyName
$sourceFiles = Get-ChildItem $project.Directory -Filter *.cs -Recurse
foreach($sourceFile in $sourceFiles) {
if ($visitedFiles.Contains($sourceFile.FullName)) {
continue
}
$visitedFiles[$sourceFile.FullName]=1
$content = Get-Content $sourceFile.FullName
Write-Verbose "Processing source file: $sourceFile.FullName"
if($content[0].StartsWith("// YourLibrary SDK")) {
for($i = 0; $i -lt 8; $i++) {
$content[$i] = $null
}
}
$relativeFilename = $sourceFile.FullName.Remove(0, $sourceRoot.Length)
$preface = "// YourLibrary SDK`n" + `
"// $relativeFilename`n" + `
"// $assemblyName, Version $versionNumber, Published $today`n" + `
"// (c) Copyright YourCompany`n" + `
"// --------------------------------------------------------------------------------`n" + `
"`n" + `
"`n"
Set-Content $sourceFile.FullName -value $preface, $content
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment