TheBuzzSaw
TheBuzzSaw

Reputation: 8836

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?

Upvotes: 7

Views: 1996

Answers (1)

DavidG
DavidG

Reputation: 119076

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'" />

Upvotes: 13

Related Questions