Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 315
TheBuzzSaw Avatar asked Oct 11 '19 23:10

TheBuzzSaw


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'" />
like image 61
DavidG Avatar answered Sep 30 '22 19:09

DavidG