Heya! Im all out of ideas. I need some help. Short story: I want to run a .exe from a nuget-package only once, before build, in a multitarget project. This is how I would usually do this for the projects that are not multitarget: <Target Name="PreBuild" BeforeTargets="PreBuildEvent"> <Exec WorkingDirectory="$(MSBuildProjectDirectory)\Localization" Command=""$(PkgMyNuget)\tools\MyNuget\MyNuget.exe" /public /ns:MyNameSpace" /> </Target>
This is my test setup where I only do Message for debugging purposes: <PropertyGroup> <TargetFrameworks>net48;net6.0</TargetFrameworks></PropertyGroup><ItemGroup> <PackageReference Include="MyNuget" version="1.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>none</IncludeAssets> </PackageReference></ItemGroup>
This works except it is running for each of the target frameworks: <Target Name="PreBuild" BeforeTargets="PreBuildEvent"> <Message Text="PkgMyNuget: $(PkgMyNuget)" Importance="high" /></Target>
Result: PkgMyNuget: D:\Nuget\MyNuget\1.0.0PkgMyNuget: D:\Nuget\MyNuget\1.0.0
For it to run only once i can do this: <Target Name="OuterPreBuild" BeforeTargets="DispatchToInnerBuilds"> <Message Text="PkgMyNuget: $(PkgMyNuget)" Importance="high" /></Target>
Result:PkgMyNuget: From what I understand, if Im running beforeTargets DispatchToInnerBuilds, then its running to early. So, here I am, asking for some help on how to solve this. Any suggestions? Edit: I think I have found a workaround. But I would still like to see if theres any other approach to this problem since the package might not have been restored yet. <PropertyGroup> <MyNugetVersion>1.0.0</MyNugetVersion> <PkgMyNuget>$(NuGetPackageRoot)\MyNuget\$(MyNugetVersion)</PkgMyNuget> </PropertyGroup><ItemGroup> <PackageReference Include="MyNuget" version="$(MyNugetVersion)"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>none</IncludeAssets> </PackageReference></ItemGroup><Target Name="PreBuild" BeforeTargets="PreBuildEvent"> <Exec WorkingDirectory="$(MSBuildProjectDirectory)\Localization" Command=""$(PkgMyNuget)\tools\MyNuget\MyNuget.exe" /public /ns:MyNameSpace" /> </Target>
What I did not mention is that we are using CPM. The first property group I can have inDirectory.Packages.props (and ofc skip the version in the csproj and have $(MyNugetVersion) on the version in .props) |