.NET Core Conditional publishing depending on Published Target Runtime

Viewed 408

Is there a way to check what the published target runtime is? There are different sets of deploy files that I want to copy to the publish directory depending on whether the target runtime is Linux or Windows. What would be the macro/property for checking the published runtime? I'm attempting to do something like the below:

<Target Name="CopyFiles" AfterTargets="Publish" Condition="$(TargetRuntime) == Linux-64">
    <MakeDir Directories="$(PublishDir)" Condition="!Exists('$(PublishDir)Deploy')" />
    <Copy SourceFiles ="$(SolutionDir)*" DestinationFolder ="$(PublishDir)Deploy" />
</Target>
1 Answers

You are likely looking for $(RuntimeIdentifier) - e.g.:

<ItemGroup Condition="'$(RuntimeIdentifier)' == 'linux-x64'">
  <Content Update="foo.json" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>

(Assuming it is a content item, could be None as well depending on the project type)

Related