gpt4 book ai didi

npm - DotNet Core 2.0 WebDeploy 对 npm build 的调用在 Publish 上不起作用

转载 作者:行者123 更新时间:2023-12-04 21:38:40 32 4
gpt4 key购买 nike

我过去曾使用一种策略,我们的后端开发人员在 VisualStudio 中工作,我们的 UI 人员纯粹在 Sublime/VSCode 等中工作。在 VS2017 中发布网站期间,我使用发布目标首先运行 npm install,然后运行 ​​npm build(捆绑我们的 app.js 逻辑),然后将该前端内容包含到 WebDeploy 的后端包中。

我正在尝试在 dotnet 核心 2.0 项目中复制它,但是构建前端的发布目标调用从未被调用(即你永远不会看到 echo 命令内容,npm 安装/构建也不会运行)。 . 所以在发布时不包含 UI 资源,除非我之前手动运行构建过程以从 VSCode 生成它们并且它们已经存在于磁盘上。 IE。复制 UI 生成的文件效果很好(如果它们存在的话)...但是 VS2017 从不调用 npm 命令来构建资源?

虽然有点繁琐,但这在几个 .NET 4.6+ 项目中效果很好。我刚刚将完全相同的逻辑复制到 Core 2.0 项目,但出于某种原因,它没有按我预期的方式工作?有什么想法吗?

例如我的 ProjectDeploy.pubxml 文件包含(在最终结束“项目”标签之前的底部):

  <!-- 
make sure that we BUILD the UI *before* we copy the files to the package
See: http://byalexblog.net/using-msbuild-to-deploy-composite-web-application
See: http://www.codecadwallader.com/2015/03/15/integrating-gulp-into-your-tfs-builds-and-web-deploy/
-->
<PropertyGroup>
<!-- relative path back out of 'current' folder to outside location of the UI files -->
<FrontEndLocalPath>..\..\src-app</FrontEndLocalPath>
</PropertyGroup>
<!--
Build the mobile web app assets , ensuring that all packages are installed and up to date
-->
<Target Name="BuildFrontEnd">
<Exec Command="echo Got Here also Dale" />
<!-- requires that NPM be installed in environment variables, which we will assume rather than use the NPM env variable above -->
<!-- call npm install -->
<exec command="npm install" WorkingDirectory="$(FrontEndLocalPath)" />
<!-- Run npm run build to populate the www folder with your latest minified production build. -->
<exec command="npm run build" WorkingDirectory="$(FrontEndLocalPath)" />
</Target>
<!--
On each package and/or deploy (because they are different), we want to ensure that we bundle up all the Angular dist code and include that as part of the package / deployment.
See: https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/deploying-extra-files
-->
<Target Name="CustomCollectFiles" DependsOnTargets="BuildFrontEnd">
<Exec Command="echo Got Here Dale" />
<ItemGroup>
<_CustomFiles Include="$(FrontEndLocalPath)\www\**\*" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>wwwroot\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>CustomCollectFiles;</CopyAllFilesToSingleFolderForPackageDependsOn>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>CustomCollectFiles;</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>

最佳答案

好的,所以我不知道这是否特定于新的 dotnetcore 2.0,但我点击了这些链接并使一切正常运行。使用内置的 VS2017 SPA 模板,我现在不再遵循我们在 .NET 4.6 中使用的方法来修改 .pubxml 发布配置文件以尝试构建/复制文件。取而代之的是 gulp/webpack build-SPA-and-copy- files-on-build 逻辑包含在 .csproj 文件中。请注意,这样做的好处是您可以快速构建解决方案而无需每次都构建 UI,但仍然会在部署时捆绑所有新的 UI 更改。我的工作示例如下链接:

https://stackoverflow.com/a/44429390/4413476

<PropertyGroup>
<!--
relative path back out of 'current' folder to outside location of the
custom single page app UI files (and any other paths we require)
-->
<FrontEndLocalPath>..\..\src-app</FrontEndLocalPath>
</PropertyGroup>

<Target Name="DebugBuildSPA" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('wwwroot\dist') ">
<!-- Ensure Node.js is installed -->
<Exec Command="node --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
<Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />

<!--
In development, the dist files won't exist on the first run or when cloning to
a different machine, so rebuild them if not already present.
-->
<Message Importance="high" Text="Performing first-run Webpack build..." />
<exec command="npm install" WorkingDirectory="$(FrontEndLocalPath)" />
<exec command="npm run build" WorkingDirectory="$(FrontEndLocalPath)" />
</Target>

<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish" Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
<!-- Build our single page application content -->
<exec command="npm install" WorkingDirectory="$(FrontEndLocalPath)" />
<exec command="npm run build" WorkingDirectory="$(FrontEndLocalPath)" />
<ItemGroup>
<Dist Include="$(FrontEndLocalPath)\www\**;" />
</ItemGroup>
<Copy SourceFiles="@(Dist)" DestinationFolder="$(PublishDir)\wwwroot\%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>

关于npm - DotNet Core 2.0 WebDeploy 对 npm build 的调用在 Publish 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47697069/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com