Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Running a PreBuild target only once if multitarget#11479

Unanswered
AlexanderRydberg asked this question inQ&A
Discussion options

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="&quot;$(PkgMyNuget)\tools\MyNuget\MyNuget.exe&quot; /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="&quot;$(PkgMyNuget)\tools\MyNuget\MyNuget.exe&quot; /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)

You must be logged in to vote

Replies: 0 comments

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@AlexanderRydberg

[8]ページ先頭

©2009-2025 Movatter.jp