C
C#3y ago
swagrid

Run msbuild target only during dotnet pack

Is it possible to run a msbuild target in a csproj only when it's packaged to a nuget package, i.e. dotnet pack MyProject should cause the target to run while dotnet build MyProject shouldn't.
1 Reply
swagrid
swagridOP3y ago
Hmm I have a target right now that looks like this
<Target Name="InstallNative" BeforeTargets="Pack" ...>
<Target Name="InstallNative" BeforeTargets="Pack" ...>
which isn't executed
<Target Name="InstallNative" BeforeTargets="Pack" Condition=" $(SkipNativeBuild) != 'true' ">
<Message Importance="high" Text=" ------------------------ Install --------------------------" />
<Exec Command="cmake --config $(Configuration) --install out/build/$(CMakeConfigPreset)" WorkingDirectory="$(NativeRootDir)" />
</Target>
<Target Name="InstallNative" BeforeTargets="Pack" Condition=" $(SkipNativeBuild) != 'true' ">
<Message Importance="high" Text=" ------------------------ Install --------------------------" />
<Exec Command="cmake --config $(Configuration) --install out/build/$(CMakeConfigPreset)" WorkingDirectory="$(NativeRootDir)" />
</Target>
removing the condition doesn't change anything that didn't help. but i just found out its my project properties. i do
<SkipCopyBuildProduct>true</SkipCopyBuildProduct>
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<GenerateDependencyFile>false</GenerateDependencyFile>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
<IncludeBuildOutput>false</IncludeBuildOutput>
<SkipCopyBuildProduct>true</SkipCopyBuildProduct>
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<GenerateDependencyFile>false</GenerateDependencyFile>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
<IncludeBuildOutput>false</IncludeBuildOutput>
to not generate and package any dotnet assembly. but this seems to skip pack entirely yeah if i remove these properties the target runs
Want results from more Discord servers?
Add your server