Skip to content

Instantly share code, notes, and snippets.

@lkaczanowski
Created October 18, 2013 07:17
Show Gist options
  • Select an option

  • Save lkaczanowski/7037672 to your computer and use it in GitHub Desktop.

Select an option

Save lkaczanowski/7037672 to your computer and use it in GitHub Desktop.
Powershell nuget script to copy log4net.config file to project depending on project type
param($installPath, $toolsPath, $package, $project)
$projectItems = $project.ProjectItems
$isWPFProject = Select-String -Simple "{60DC8134-EBA5-43B8-BCC9-BB4BC16C2548}" $project.FullName #WPF project guid
$isWinFormsProject = Select-String -Simple "FlavorProperties" $project.FullName #WinForms project doesn't support FlavorProperties so should be empty
if(([string]::IsNullOrEmpty($isWPFProject) -eq $false) -or ([string]::IsNullOrEmpty($isWinFormsProject) -eq $true)) {
#terminal app project
Write-Host "Detected terminal application project (WebForms or WPF)"
$projectItems.Item("log4net.config").Delete()
$projectItems.Item("log4net.template.config").Delete()
Write-Host "Copying log4net.config from TerminalAppConfig folder..."
$configPath = $projectItems.Item('TerminalAppConfig').ProjectItems.Item('log4net.config').Properties.Item("FullPath").Value
$configPath2 = $projectItems.Item('TerminalAppConfig').ProjectItems.Item('log4net.template.config').Properties.Item("FullPath").Value
$projectItems.AddFromFileCopy($configPath)
$projectItems.AddFromFileCopy($configPath2)
}
else {
#other project (ex. library or web)
Write-Host "Detected non-terminal application project (other than WebForms and WPF)"
}
Write-Host "Setting CopyToOutputDirectory to 1..."
$projectItems.Item("log4net.config").Properties.Item("CopyToOutputDirectory").Value = 1
$projectItems.Item("log4net.template.config").Properties.Item("CopyToOutputDirectory").Value = 1
Write-Host "Deleting TerminalAppConfig folder..."
$projectItems.Item("TerminalAppConfig").Delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment