Skip to content

Instantly share code, notes, and snippets.

@nikolay-pshenichny
Created May 9, 2015 01:49
Show Gist options
  • Save nikolay-pshenichny/560905f7e8c300895686 to your computer and use it in GitHub Desktop.
Save nikolay-pshenichny/560905f7e8c300895686 to your computer and use it in GitHub Desktop.
Modify "Conditional compilation symbols" from NuGet install.ps1 script
param($installPath, $toolsPath, $package, $project)
if ($project -ne $null)
{
$configuration = $project.ConfigurationManager | Where-Object {$_.ConfigurationName -eq "Debug"}
if ($configuration -ne $null)
{
$oldValue = $configuration.Properties.Item("DefineConstants").Value
$newValue = $newValue + ";" + "HELLO_WORLD"
$configuration.Properties.Item("DefineConstants").Value = $newValue
}
$project.Save()
}
# Notes:
# - This example is way to simplistic
#
# Required modifications:
# - check if the Symbol that you want to inject is already there.
# - check $project.IsDirty if needed
# In Package Manager Console:
$dte = [System.Runtime.InteropServices.Marshal]::GetActiveObject("VisualStudio.DTE.12.0")
$p = $dte.Solution.Projects | Where-Object {$_.ProjectName -eq "YourProjectName"}
# OR
$p = Get-Project
# And then...
$c = $p.ConfigurationManager | where-object {$_.ConfigurationName -eq "Release"}
$oldValue = $c.Properties.Item("DefineConstants").Value
$newValue = $oldValue + ";HELLO_WORLD"
$c.Properties.Item("DefineConstants").Value = $newValue
$p.Save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment