生成的包文件不包含在已发布的工件中
Generated bundle files are not included in published artifact
我有一个 asp.net (.Net 4) 程序,我最近在其中集成了 ReactJS 页面。我已经使用 Webpack 这样做了。
该项目有 post-build 事件来构建我的 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 包仍未包含在已发布的管道工件中。
我可以在日志中看到 post-构建事件 运行(我什至尝试将其切换到预构建)并且生成了 JS 包。
但是,当我解压缩项目并查看 dist 文件夹时:它是空的。
管道的配置在我们的工作流程中并不是什么新鲜事,它已经存在了一年多并且适用于所有其他用例。到目前为止唯一的问题是:'dist' 文件夹中的 JS 包没有转移到发布。
请注意,我们不托管管道代理,我们使用 'windows-latest' Azure 代理,我们使用 VS 2019 构建。我的猜测是,按照构建事件的顺序,文件列表包含在发布工件中的可能是在生成 JS 文件之前编写的。
任何帮助都会很棒,
提前致谢
您可以尝试将以下 属性 个组添加到您的 csproj 文件中,如果它们不在 csproj 中。
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
AfterBuild;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<PropertyGroup>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
AfterBuild;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
有关详细信息,请参阅 this blog。
如果上述方法无效。您还可以在发布构建工件之前添加以下任务。
Extract files task解压工件包,
并添加一个copy file task将dist文件夹复制到artifacts,
然后添加 archive files 任务以再次压缩工件。
我有一个 asp.net (.Net 4) 程序,我最近在其中集成了 ReactJS 页面。我已经使用 Webpack 这样做了。
该项目有 post-build 事件来构建我的 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 包仍未包含在已发布的管道工件中。
我可以在日志中看到 post-构建事件 运行(我什至尝试将其切换到预构建)并且生成了 JS 包。 但是,当我解压缩项目并查看 dist 文件夹时:它是空的。
管道的配置在我们的工作流程中并不是什么新鲜事,它已经存在了一年多并且适用于所有其他用例。到目前为止唯一的问题是:'dist' 文件夹中的 JS 包没有转移到发布。
请注意,我们不托管管道代理,我们使用 'windows-latest' Azure 代理,我们使用 VS 2019 构建。我的猜测是,按照构建事件的顺序,文件列表包含在发布工件中的可能是在生成 JS 文件之前编写的。
任何帮助都会很棒, 提前致谢
您可以尝试将以下 属性 个组添加到您的 csproj 文件中,如果它们不在 csproj 中。
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
AfterBuild;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<PropertyGroup>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
AfterBuild;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
有关详细信息,请参阅 this blog。
如果上述方法无效。您还可以在发布构建工件之前添加以下任务。
Extract files task解压工件包,
并添加一个copy file task将dist文件夹复制到artifacts,
然后添加 archive files 任务以再次压缩工件。