C
C#5mo ago
Otozinclus

Include files only on a specific platform

Hey! The project I am working on, uses FFmpeg, but because there is no official release of FFmpeg for Windows on Arm, I need to add an unofficial build of FFmpeg for WoA into the build folder in order for it to work. I did that by adding following code to the .csproj file and it works: <ItemGroup> <Content Include="ffmpeg.exe"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> <Content Include="ffprobe.exe"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup> However, this is totally unnecessary for any other platform but Windows Arm64, therefore my goal is that these files only get added to the build, if the user is building for WoA. I tried that by adding a condition after the ItemGroup: <ItemGroup Condition="'$(RuntimeIdentifier)' == 'win-arm64'"> Sadly, this does not work. It does build the project, but without these files, despite building on WoA. I then tried the opposite, excluding every other platform with != and that way it builds for WoA, but also for every other platform. If anyone could explain why this happens, I would be very glad!
4 Replies
Anton
Anton5mo ago
print that variable to see what it actually has the idea is correct the order might be relevant, check if it is set in target or the sdk experimentally
Otozinclus
OtozinclusOP5mo ago
How can I do this?
Anton
Anton5mo ago
<Target Name="MyDebugPrintTask" BeforeTargets="Build">
<Message Importance="High" Text="The value of the variable is $(RuntimeIdentifier)" />
</Target>
<Target Name="MyDebugPrintTask" BeforeTargets="Build">
<Message Importance="High" Text="The value of the variable is $(RuntimeIdentifier)" />
</Target>
I don't know if it's possible to check this in that way Well actually yeah it is Like this
<PropertyGroup>
<CurrentValueOfVariable>$(RuntimeIdentifier)</CurrentValueOfVariable>
</PropertyGroup>
<Target Name="MyDebugPrintTask" BeforeTargets="Build">
<Message Importance="High" Text="The value of the variable is $(CurrentValueOfVariable)" />
</Target>
<PropertyGroup>
<CurrentValueOfVariable>$(RuntimeIdentifier)</CurrentValueOfVariable>
</PropertyGroup>
<Target Name="MyDebugPrintTask" BeforeTargets="Build">
<Message Importance="High" Text="The value of the variable is $(CurrentValueOfVariable)" />
</Target>
Note that CurrentValueOfVariable is global You can't make local variables in msbuild
wasabi
wasabi5mo ago
So, the trick here is you need to have your project operate in two modes: arch-indepedent and arch-dependent. Because a .NET project can be built in both ways. Library projects never build with RuntimeIdentifier set. Executable projects can be built with RuntimeIdentifier set: but only usually when publishing with --rid. So, you need to support both. You need to, when RID is not set, copy ALL the arch files into the right places, so you can pick the correct one at runtime. And when RID IS set, you can just copy one.
Want results from more Discord servers?
Add your server