在 csproj 中,我可以根据运行时标识符有条件地包含一个文件吗?

The*_*Saw 5 c# csproj .net-core

假设我以这些方式构建我的项目。

dotnet publish -r win-x86
dotnet publish -r linux-musl-x64
Run Code Online (Sandbox Code Playgroud)

有没有办法在我的.csproj文件中自动包含基于所选RID的本机 DLL ?

Dav*_*idG 8

您只需要Condition在 csproj 文件中要控制的元素上有一个。例如:

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

<PackageReference Include="MyLibrary.Windows" Version="1.0.0" 
    Condition="'$(RuntimeIdentifier)'=='win-x64'" />
Run Code Online (Sandbox Code Playgroud)