Как изменить csproj PublishRunWebpack для включения статических файлов из внешнего каталога - PullRequest
0 голосов
/ 30 апреля 2019

Я начал с ASP.NET Core Web Application -> Angular SPA, но я переместил угловое приложение в отдельный репозиторий вне csproj.

Итак, моя структура папок выглядит следующим образом:

frontend
  dist

backend
  wwwroot
  backend.csproj

Теперь я хочу изменить csproj, чтобы опубликовать копию frontend/dist/**/*.* в $(outputDirecory)/ClientApp/dist/**/*.*

Как мне изменить цель PublishRunWebpack, чтобы скопировать эти файлы:

  <PropertyGroup>
    <SpaRoot>../Frontend</SpaRoot>
  </PropertyGroup>

  <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />

    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
      <!-- Include the newly-built files in the publish output -->
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">


        <!-- THIS NEEDS TO BE CHANGED (I guess) -->
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>

1 Ответ

0 голосов
/ 01 мая 2019

Согласно вашему описанию я обнаружил, что папка внешнего интерфейса не будет копироваться в папку PubTmp \ Out. Это означает, что приложение forentend spa не будет копировать в папку публикации.

Я предлагаю вам попробовать создать новую цель, чтобы скопировать папку forentend dist в папку публикации.

Подробнее, вы можете обратиться к ниже кодов:

      <Target Name="PublishRunWebpack" AfterTargets="CopyFileToOutput">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build -- --prod" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />

    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
      <DistFiles Include="$(SpaRoot)node_modules\**" Condition="'$(BuildServerSideRenderer)' == 'true'" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>
  <Target  Name="CopyFileToOutput"  AfterTargets="ComputeFilesToPublish">
    <ItemGroup>
      <_CopyItems Include="obj\Release\netcoreapp2.2\PubTmp\Frontend\**\*.*" />
    </ItemGroup>
    <Copy
    SourceFiles="@(_CopyItems)"
    DestinationFolder="obj\Release\netcoreapp2.2\PubTmp\Out\Frontend\dist"
    />
  </Target>
...