I automatically generate Nuget packages when building my .Net Core class libraries. The version of these packages is taken from the PackageVersion property in the .csproj files.
Issue is that I want to overwrite the value of these PackageVersion properties in a target, while the build runs. I tried the following:
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<PropertyGroup>
<PackageVersion>5.0.99</PackageVersion>
</PropertyGroup>
</Target>
(the 5.0.99 is just a simple value for this example)
However, this seems to do nothing. The initial value of the PackageVersion property continues to be used as the version of the Nuget package.
How can I overwrite the value of the PackageVersion property in a target so that the new value is used during generation of the Nuget package?
You can extends GetPackageVersionDependsOn property in your csproj file.
<PropertyGroup>
<GetPackageVersionDependsOn>MyCustomTask;$(GetPackageVersionDependsOn)</GetPackageVersionDependsOn>
</PropertyGroup>
<Target Name="MyCustomTask">
<PropertyGroup>
<PackageVersion>5.0.99</PackageVersion>
</PropertyGroup>
</Target>
This works also by importing a custom targets file with the above code.
<Import Include="../MyCustom.targets" />
But it does not work when using a custom nuget package that installs a targets import.
Nuget package *.targets files are not imported during msbuild -t:pack
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With