【发布时间】:2020-10-15 20:10:55
【问题描述】:
我有一个 asp.net (.Net 4) 程序,我最近在其中集成了 ReactJS 页面。为此,我使用了 Webpack。
该项目有构建后的事件来构建我的 JS 包,如下所示:
npm install
npm run build
我的 webpack 配置使得捆绑包被写入一个名为 dist 的文件夹中。
在开发中,一切都很好。当我构建解决方案(以及相关项目)时,捆绑包是正确构建的。
但是,当我尝试使用 Visual Studio 发布功能在发布模式下发布我的项目时,我很快注意到我的 JS 包从我的 dist 文件夹中丢失了。
然后我对我的 csproj 进行了一些调整来解决这个问题,如下所示:
I first included the dist folder in its entirety to my project, as I only had included one file from the folder into the project :
<Content Include="dist\**">
<Visible>false</Visible>
</Content>
I then added a Target step at the end of the csproj to include the content of the folder in the published package :
<Target Name="AfterBuild">
<ItemGroup>
<BundleFiles Include="dist\**" />
<FilesForPackagingFromProject Include="%(BundleFiles.Identity)">
<DestinationRelativePath>%(BundleFiles.Identity)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
在这些更改之后,我可以发布我的 Web 应用程序,并且会生成捆绑包(在构建事件之后),然后将其包含到该发布文件夹中。
所以现在,问题... 我们使用 Azure DevOps 管道来构建我们的生产版本。即使在我对 csproj 进行了更改之后,JS 包也不会包含在管道的已发布工件中。
我可以看到日志中运行了构建后事件(我什至尝试将其切换为预构建)并且生成了 JS 包。 但是,当我解压缩项目并查看 dist 文件夹时:它是空的。
管道的配置在我们的工作流程中并不是什么新鲜事,它已经存在了一年多,并且适用于所有其他用例。到目前为止唯一的问题是这个问题:'dist' 文件夹中的 JS 包没有被转移到发布中。
请注意,我们不托管管道代理,我们使用“windows-latest”Azure 代理并使用 VS 2019 进行构建。我的猜测是,按照构建事件的顺序,文件列表是发布工件中包含的可能是在生成 JS 文件之前编写的。
任何帮助都会很棒, 提前致谢
【问题讨论】:
标签: webpack azure-devops msbuild