Question: Steps to reproduce
On windows it works fine with this command :

```
<PropertyGroup>
    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
    <PreBuildEvent>IF NOT EXIST "$(TargetDir)DataFiles" MKDIR "$(TargetDir)DataFiles"</PreBuildEvent>
    <PostBuildEvent>FOR /R "$(SolutionDir)\Api.Tests\Scenarios" %25%25f IN (*.json) DO COPY "%25%25f" "$(TargetDir)DataFiles\" /Y</PostBuildEvent>

  </PropertyGroup>

```

On linux , I have this kind of error 

```
Build FAILED.
[12:44:39][Step 1/1] 
[12:44:39][Step 1/1] /usr/share/dotnet/sdk/2.1.302/Microsoft.Common.CurrentVersion.targets(1331,5): error MSB3073: The command "IF NOT EXIST "DataFiles" MKDIR "DataFiles"" exited with code 127. [/opt/jetbrains/buildAgent/work/4fc9032bf5656724/Api.Tests/Api.Tests/Api.Tests.csproj]
[12:44:39][Step 1/1]     0 Warning(s)
[12:44:39][Step 1/1]     1 Error(s)

```

Answer: 
Your post build event uses `CMD.EXE` specific code - also known as (Windows) BATCH commands. In other words it is platform specific.

Best thing is to use MSBuild built-in features to copy files:

* Remove the PreBuildEvent and PostBuildEvents properties
* Add the following inside the "Project" tag of your project file (best at the end).

```
<PropertyGroup>
   <BuildDependsOn>
   $(BuildDependsOn);_CopyAuxFiles
   </BuildDependsOn>
</PropertyGroup>

<Target Name="_CopyAuxFiles">
    <MakeDir Directories="$(TargetDir)DataFiles"/>
    <ItemGroup>
       <Files Include="$(SolutionDir)\Api.Tests\Scenarios\*.json"/>
    </ItemGroup>
    <CopyFile SourceFiles="@(Files)" DestinationFolder="$(TargetDir)DataFiles"/>
</Target>

```

You might need to replace "$(TargetDir)" with "$(OutputPath)".
I have resolved it by

```
    <Target Name="CopyScenarios" AfterTargets="Build">
    <ItemGroup>  
      <Scenarios Include="$(ProjectDir)/Scenarios/**/*.json" />
    </ItemGroup>
    <Copy SourceFiles="@(Scenarios)" DestinationFiles="@(Scenarios->'$(TargetDir)DataFiles/%(Filename)%(Extension)')" SkipUnchangedFiles="false" />
  </Target>

```