In csproj, can I conditionally include a file based on runtime identifier?

Viewed 970

Suppose I build my project these ways.

dotnet publish -r win-x86
dotnet publish -r linux-musl-x64

Is there a way in my .csproj file to automatically include a native DLL based on the chosen RID?

1 Answers

You just need a Condition on the element you want to control in the csproj file. For example:

<PackageReference Include="MyLibrary.Linux" Version="1.0.0" 
    Condition="'$(RuntimeIdentifier)'=='linux-x64'" />

<PackageReference Include="MyLibrary.Windows" Version="1.0.0" 
    Condition="'$(RuntimeIdentifier)'=='win-x64'" />
Related