I'm having a multiple targeting project using a script that generates classes out of a XSD. That should only be done once - for all build targets.
I found that SO-question but this solution does not work.
My filtered csproj contains these entries:
<PropertyGroup>
<TargetFrameworks>net472;net60-windows</TargetFrameworks>
...
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="call $(ProjectDir)..\..\..\Scripts\Python\XsdClassConverter2-Invoke.bat ..." />
</Target>
I tried to change BeforeTargets
and Name
to <Target Name="OuterPreBuild" BeforeTargets="DispatchToInnerBuilds">
as suggested in linked post. But this does not work.
I'm sure that I'm missing something.
I tried to find all possible entries for BeforeTargets
and found that link. But all of the possibilities does not sound like the setting that I'm looking for.
How do I've to call/setup my script to run only once?
Build environment is VS2022.
EDIT
I've a working solution:
<Target Name="GenerateXsdsCore">
<Exec Command="call "$(ProjectDir)..\..\..\Scripts\Python\XsdClassConverter2-Invoke.bat" "$(ProjectDir)Csv\Persistence\V1\V1_0.CsvCommon.xsd" -n "Toolkit.IO.Framework.Csv.Persistence.V1" --field-specified-as-compare-default" />
<Exec Command="call "$(ProjectDir)..\..\..\Scripts\Python\XsdClassConverter2-Invoke.bat" "$(ProjectDir)Licensing\Osi\Persistence\V1\V1_0.OpenSourceLicenseInformation.xsd" -n "Toolkit.IO.Framework.Licensing.Osi.Persistence.V1" --field-specified-as-compare-default" />
</Target>
<Target Name="GenerateXsds" BeforeTargets="DispatchToInnerBuilds;BeforeBuild">
<MSBuild Projects="$(MSBuildProjectFile)" Targets="GenerateXsdsCore" Properties="TargetFramework=once" />
</Target>
The interesting point is TargetFramework=once
. But this solution does not look like it should be done.