0

Can a NuGet package define a preprocessor symbol for the consuming project? And if so, how?

1 Answer 1

1

If your package (My.ExamplePackage) contains an MSBuild file named like the package name + .targets in the build directory (so build\MyExamplePackage.targets), you can use it to amend the DefineConstants property that may have been set to defaults or reset in the project:

<Project>
  <PropertyGroup>
    <DefineConstants>$(DefineConstants);MY_PREPOCESSOR_SYMBOL</DefineConstants>
  </PropertyGroup>
</Project>

While the package can contain both a .props and .targets file, the .targets file will be imported after the main body of the csproj file being built so if it the project re-sets DefineConstants (meaning not adding to it by prepending $(DefineConstant);), the .targtes file has a chance of adding to this property.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.