【问题标题】:dotnet publish runs before prepublish finishesdotnet publish 在预发布完成之前运行
【发布时间】:2016-12-14 06:39:31
【问题描述】:

我的dotnet publish 命令在执行发布步骤之前不会等待预发布完成。结果缺少已发布的内容。

在我的场景中,prepublish 运行 webpack 来生成 wwwroot。但是发布发生在预发布完成之前,导致缺少 wwwroot。如果我再次发布,因为 wwwroot 现在存在,它会正确发布。

这里是相关的 project.json 部分

"publishOptions": {
    "include": [
        "appsettings.json",
        "Views",
        "web.config",
        "wwwroot",
        "AppStore/dist"
    ],
    "exclude": [
        "wwwroot/dist/*.map"
    ]
  },


  "scripts": {
      "prepublish": [
        "npm install",
        "node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod",
        "node node_modules/webpack/bin/webpack.js --env.prod"
      ],
  },

其他人看到了吗?运行 Dotnet Core 1.0.0-preview2-1-003177

【问题讨论】:

    标签: webpack .net-core publish


    【解决方案1】:

    我在 dotnet/cli 上发现了 this 问题,它描述了您的行为。在 aspnet/websdk 存储库中有一个 follow up,它还描述了一种解决方法:

    <Target Name="PrepublishScript" AfterTargets="ComputeFilesToPublish">
        <!-- Exclude old script and font files from publish output-->
        <ItemGroup>
            <PrevScriptFiles Include="wwwroot\**" />
            <ResolvedFileToPublish Remove="@(PrevScriptFiles->'%(FullPath)')" />
        </ItemGroup>
    
        <Exec Command="npm install" />
        <Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
        <Exec Command="node node_modules/webpack/bin/webpack.js --env.prod" />
    
        <!-- Include the newly-built files in the publish output -->
        <ItemGroup>
            <DistFiles Include="wwwroot\**" />
            <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
                <RelativePath>%(DistFiles.Identity)</RelativePath>
                <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
            </ResolvedFileToPublish>
        </ItemGroup>
    </Target>
    

    最新的cmets显示,这个很久不用了:

    此更改已在最新的 CLI 中可用(并且应该在即将发布的 VS 版本中可用)。

    但无论如何,只是想发布解决方法......

    【讨论】:

      猜你喜欢
      • 2019-09-18
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-10
      相关资源
      最近更新 更多