I have a NuGet package that contains a PowerShell script which sets a conditional compilation symbol on the target project when the package is installed. This works fine for all projects except for those that use project.json files (e.g. .NET Core, UWP).
My script accesses the $project.ConfigurationManager
instances of the target project, and adds the symbol to the DefineConstants
entry if necessary. This does not work for projects with project.json files - in fact, I cannot even see the $project
object when I try to access a .NET Core project via PowerShell. The following picture illustrates this: whereas a classic .NET and PCL project are accessible, the last System.__ComObject
probably represents the .NET Core project that cannot be accessed.
So how can I set a conditional compilation symbol in a .NET Core project programmatically? Is there another way to do that instead of using an install.ps1 script? I know that, basically, I have to find the project JSON file and add the following entry if not present
"buildOptions": {
"define": [ "MY_CONDITIONAL_COMPILATION_SYMBOL" ]
}
but I'm stuck on how to get there.