0
votes

I have a shared.{Environment}.json file that is added as linked files in several .Net core 2.1 projects. When project is build or published file gets copied to output directory, in case of release its fine but on debug it doesn't work as when project run it looks up for that file in project directory not in output directory.

Whats the proper way to solve this issue for both debug and publish?

1

1 Answers

0
votes

For linked files, it will not exist under the project directory.

For a workaround, you could try to copy the file with task in csproj like below:

  <ItemGroup>
    <Content Include="..\MVCPro\shared.{Environment}.json">
      <Link>shared.{Environment}.json</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
   </ItemGroup>

   <Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
      <Copy SourceFiles="..\MVCPro\shared.{Environment}.json"  DestinationFolder=".\" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" />
   </Target>