Introduction
For a recent project, I wanted to add a property to the consuming applications from within my NuGet package. This prevents making a pull request for every consuming application with a .csproj change.
š Please note in this example the NuGet package has the ID:
MyProject.ExampleNuGet
, so replace that value for your nuget package. The consuming application is MyProject.ConsumingWebApi
.
NuGet file structure
|
|
MyProject.ExampleNuGet.props
The NuGet package has a .props-file to enforce some properties to the consumers.
|
|
MyProject.ExampleNuGet.csproj
Important is to set the build action of the MyProject.ExampleNuGet.props
file to package it to the build directory. See the example below:
|
|
Conclusion
When installing this package on for example MyProject.ConsumingWebApi
a file is generated in de build folder MyProject.ConsumingWebApi.csproj.nuget.g.targets
.
This ensures the setting is on when building MyProject.ConsumingWebApi
.
References
I used the following resources to fix my problem.