title: ASP.NET Core & SPA - client files not published when the client is outside of the server folder
body: <p>I have a project which has separate client and server folders and my goal is to include client files during the server's publish process. The folder structure looks like this</p>
  <pre><code>|- server
  |  |- src
  |     |- MyProject
  |        |- MyProject.csproj
  |- client
     |- src
        |- dist
  
  </code></pre>
  <p>Using the default SPA template which defines <code>SpaRoot</code>, in my case <code>../../../client/src/</code> and the following item group definition</p>
  <pre><code>&lt;ItemGroup&gt;
      &lt;DistFiles Include=&quot;$(SpaRoot)dist\**; $(SpaRoot)dist-server\**&quot; /&gt;
      &lt;DistFiles Include=&quot;$(SpaRoot)node_modules\**&quot; Condition=&quot;'$(BuildServerSideRenderer)' == 'true'&quot; /&gt;
      &lt;ResolvedFileToPublish Include=&quot;@(DistFiles-&gt;'%(FullPath)')&quot; Exclude=&quot;@(ResolvedFileToPublish)&quot;&gt;
          &lt;RelativePath&gt;%(DistFiles.Identity)&lt;/RelativePath&gt;
          &lt;CopyToPublishDirectory&gt;PreserveNewest&lt;/CopyToPublishDirectory&gt;
          &lt;ExcludeFromSingleFile&gt;true&lt;/ExcludeFromSingleFile&gt;
      &lt;/ResolvedFileToPublish&gt;
  &lt;/ItemGroup&gt;
  </code></pre>
  <p>From the logs I can see this results in copying the files elsewhere <code>Copying file from &quot;C:\MyProject\client\src\dist\img\ic_mail.svg&quot; to &quot;C:\MyProject\server\src\MyProject\obj\Release\client\src\dist\img\ic_mail.svg&quot;.</code> while the target path should be <code>C:\MyProject\server\src\MyProject\obj\Release\netcoreapp3.1\PubTmp\Out\appsettings.Development.json</code>. I'm assuming it's caused by the different parent directory because the common parent is 3 levels up the hierarchy and the files are also copied to a directory 3 levels higher than they should be.</p>
  <p>I tried prefixing the <code>SpaRoot</code> with <code>$(ProjectDir)</code>, but that did not help. My goal is to copy the files from the <code>dist</code> folder to <code>wwwroot</code> located at the root of the publish folder. I attempted to adjust the <code>ResolvedFileToPublish</code>, but I was not able to retrieve the items' relative path (relative to the <code>dist</code> folder).</p>
  <p><strong>Edit:</strong> A csproj based workaround was to copy the files manually to <code>wwwroot</code> in the <code>BeforeTargets</code> hook. Can this produce any unforeseen problems? (mostly the <code>&lt;ClientDistFile/&gt;</code>)</p>
  <pre><code>&lt;ItemGroup&gt;
      &lt;ClientDistFiles Include=&quot;$(SpaRoot)dist/**/*.*&quot;/&gt;
  &lt;/ItemGroup&gt;
  
  &lt;Target Name=&quot;PublishRunWebpack&quot; BeforeTargets=&quot;ComputeFilesToPublish&quot;&gt;
      &lt;!-- As part of publishing, ensure the JS resources are freshly built in production mode --&gt;
      &lt;Exec WorkingDirectory=&quot;$(SpaRoot)&quot; Command=&quot;yarn install&quot; /&gt;
      &lt;Exec WorkingDirectory=&quot;$(SpaRoot)&quot; Command=&quot;yarn build:$(TargetEnvironment)&quot; /&gt;
  
      &lt;Copy
          SourceFiles=&quot;@(ClientDistFiles)&quot;
          DestinationFiles=&quot;@(ClientDistFiles-&gt;'wwwroot\%(RecursiveDir)%(Filename)%(Extension)')&quot;
      /&gt;
  &lt;/Target&gt;
  </code></pre>