I have a NuGet package with a targets file which manipulates the PackageVersion depending on the current context (When the branch is master it's creates a preview).
This is working well on a normal project but when I use this in a multi target project it's not working.
How can I correct this?
I have attached a sample project. https://1drv.ms/u/s!At1IZ7t_aXW-iNRchOhliGP8dunGHg?e=11dW4F To reproduce the problem:
This creates a package of consumer with version 1.0.0. This should bie 1.0.0-xdev.
When you change Consumer.csproj so that TargetFramework is used the correct version is created
I have tried the version modification outside of the target but this leads to problems when the version number is specified in a Directory.Build.Targets file
I have tried different BeforeTargets in but nothing worked.
When you use multi-targetframeworks property like <TargetFrameworks>net461</TargetFrameworks>
, build
folder of the nuget package cannot act well and it cannot service for multi-target frameworks, only for single taget framework.
Instead, you should abandon build
and use buildCrossTargeting
.
Under BuildConfig
project, if it is a new sdk project, please use this
<ItemGroup>
<None Include="BuildConfig.targets" Pack="true" PackagePath="buildCrossTargeting" />"
</ItemGroup>
If you use nuspec file, you should use this undr the file:
<file src="BuildConfig.targets" target="buildCrossTargeting/" />
You should note that the xxx.targets
files should be under buildCrossTargeting
folder directly without any sub folders, otherwise, it will not work.